/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package jump;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Scanner;

/**
 *
 * @author korenciak4
 */
public class Jump {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner nacitaj = new Scanner(System.in);
        int pocet = 0;
        int[] pole = null;
        int[] znacky = null;
        HashSet[] mnoziny = null;

        while (nacitaj.hasNext()) {
            pocet = nacitaj.nextInt();
            if (pocet == 0) {
                return;
            }
            
            mnoziny = new HashSet[pocet+1];

            pole = new int[pocet];
            znacky = new int[pocet];
            for (int i = 0; i < pocet; i++) {
                pole[i] = nacitaj.nextInt();
            }
            
            for (int v = 0; v < pocet; v++) {
                if(znacky[v]==0){
                     znacky[v]=v+1;
                     HashSet<Integer> temp = new HashSet<>();
                     temp.add(v);
                     mnoziny[znacky[v]]=temp;                     
                }
                
                for (int j = v+1; j < pocet; j++) {
                    if((pole[j]+pole[v])==(j-v)){
                        if(znacky[j]==0){
                            znacky[j]=znacky[v];
                            mnoziny[znacky[v]].add(j);
                        }else{
                            mnoziny[znacky[j]].addAll(mnoziny[znacky[v]]);
                            mnoziny[znacky[v]]= mnoziny[znacky[j]];
                        }
                    }
                }
            }
            for (int i = pocet-1; i >=0 ; i--) {
                if(znacky[i]!=0){
                    if(mnoziny[znacky[i]].contains(0)){
                        System.out.println(i);
                        break;
                    }
                }
            }
        }
    }

}