import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/*
 * 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.
 */
/**
 *
 * @author cteam069
 */
public class Jump {

    static Pattern FIRST_NUM = Pattern.compile("\\b(\\d+)\\b");

    public static void main(String[] args) throws IOException {

        Map<Integer, List<Integer>> graph;

        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));

        while (true) {
            graph = readGraph(r);
            if (graph == null) {
                return;
            }
            for(int from=graph.size()-1; from>=0; from--){
                if(canReach(graph, from)){
                    System.out.println(from);
                    break;
                }
            }
        }

    }
    
    private static boolean canReach(Map<Integer, List<Integer>> graph, int from){
        Queue<Integer> q = new LinkedList<>();
        q.add(from);
        Set<Integer> visited = new HashSet<>();
        while(!q.isEmpty()){
            int at = q.poll();
            if(at == 0){
                return true;
            }
            visited.add(at);
            for(Integer to: graph.get(at)){
                if(! visited.contains(to)){
                    q.add(to);
                }
            }
            
            
        }
        return false;
    }

    private static Map<Integer, List<Integer>> readGraph(BufferedReader r) throws IOException {
        String first = r.readLine();
        if (first.equals("0")) {
            return null;
        }
        List<Integer> nums = findInts(r.readLine());
        Map<Integer, List<Integer>> graph = new HashMap<>();
        for (int pos = 0; pos < nums.size(); pos++) {
            List<Integer> moves = new ArrayList<>();
            for (int to = 0; to < nums.size(); to++) {
                if (Math.abs(to - pos) == nums.get(pos)+nums.get(to)) {
                    moves.add(to);
                }
            }
            graph.put(pos, moves);
        }
        return graph;
    }

    private static List<Integer> findInts(String in) {
        List<Integer> ints = new ArrayList<>();
        Matcher m = FIRST_NUM.matcher(in);
        while (m.find()) {
            ints.add(Integer.parseInt(m.group(1)));
        }

        return ints;
    }

}