#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    int N;
    int maxIndex;
    bool changed = true;
    cin >> N;
    int stones[N], jumps[N] = {0};

    while ( N != 0)
    {


        for(int i=0; i< N; i++)
        {
            cin >> stones[i];
        }

        jumps[0] =1;

        while (changed)
       {
        changed = false;

            for (int i = 0; i < N; i++)
            {

                if (jumps[i] == 1)
                {
                    changed = true;
                    jumps[i] = 2;

                    for (int j = 0; j < N; j++)
                    {
                        if (((stones[i] + stones[j]) == abs(j - i)) && jumps[j] !=2 && jumps[j] !=1 )
                            jumps[j] = 1;
                    }
                }
            }
        }
        for (int i = N -1;; i--)
            {
                if  (jumps[i] != 0)
                {
                    maxIndex = i;
                    break;
                }
            }
        cout << maxIndex << endl;
    cin >> N;
    }
    return 0;
}