/*
 * 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 wintadd;

import java.util.LinkedList;
import java.util.Scanner;

/**
 *
 * @author olesnanik2
 */
public class Yoshi {
    static public int[] spots = new int[1000000];
    static public int pebbles;
    static public boolean[] reached = new boolean[1000000];
    static public LinkedList<Integer> queue = new LinkedList<>();
    
    public static void main(String [] arguments) {
        Scanner scanner = new Scanner(System.in);
        
        while(true) {
            pebbles = scanner.nextInt();
            if (pebbles == 0) {
                break;
            }
            
            for (int p=0; p<pebbles; p++) {
                spots[p] = scanner.nextInt();
                reached[p] = false;
            }
            
            queue.clear();
            queue.add(0);
            
            int maximalReach = 0;
            
            while(!queue.isEmpty()) {
                int item = queue.removeFirst();
                maximalReach = Math.max(maximalReach, item);
                reached[item] = true;
                
                for(int i=0; i<item-spots[item]; i++) {
                    process(item, i);
                }
                for(int i=item+spots[item]; i<pebbles; i++) {
                    process(item, i);
                }
            }
            
            System.out.println(maximalReach);
        }
    }
    
    public static void process(int item, int nextItem) {
        if (reached[nextItem]) return;
        int distance = Math.abs(nextItem-item);
        if (spots[nextItem]+spots[item] == distance) {
            queue.add(nextItem);
        }
    }
}