#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;

int abs(int a)
{
    return a>0?a:-a;
}

int main()
{
    int numOfStones;
    int *spots=new int[1000000];
    int *canGetThere=new int[1000000];
    int *stack=new int[1000000];
    while(scanf("%d",&numOfStones)!=EOF)
    {
        if(numOfStones==0)
        {
            return 0;
        }
        int stackCounter=0;
        memset(canGetThere,0,sizeof(int)*numOfStones);
        for(int i=0; i<numOfStones; i++)
        {
            scanf("%d",&spots[i]);
        }
        int max=0;
        for(int i=0; i<numOfStones; i++)
        {
            if(spots[0]+spots[i]==i)
            {
                canGetThere[i]=1;
                stack[stackCounter]=i;
                stackCounter++;
            }
        }
        if(canGetThere[numOfStones-1]==1)
        {
            printf("%d\n",numOfStones-1);
            continue;
        }
        for(int i=0; i<stackCounter; i++)
        {
            for(int k=0; k<numOfStones; k++)
            {
                if(canGetThere[k]!=1&&spots[stack[i]]+spots[k]==abs(k-stack[i]))
                {
                    stack[stackCounter]=k;
                    canGetThere[k]=1;
                    stackCounter++;
                    if(k==numOfStones-1)
                    {
                        printf("%d\n",numOfStones-1);
                        break;
                    }
                }
            }
            if(i==numOfStones-1)
            {
                break;
            }
        }
        for(int i=numOfStones-1; i>=0; i--)
        {
            if(canGetThere[i]==1)
            {
                max=i;
                break;
            }
        }
        printf("%d\n",max);
    }
    delete []spots;
    delete []canGetThere;
    delete []stack;
    return 0;
}