import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.nio.charset.StandardCharsets.US_ASCII;
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.Random;
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 {

      /*  String newInString
                = "7\n"
                + generateNs(10000) + "\n"
                + "0\n";

        ByteArrayInputStream newIn = new ByteArrayInputStream(newInString.getBytes(US_ASCII));

        System.setIn(newIn);
*/
    //   Map<Integer, List<Integer>> graph;

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

        while (true) {
         //   graph = readGraph(r);
            String fir =r.readLine();
            if (fir.equals("0")) {
                return;
            }
            List<Integer> input = findInts(r.readLine());
            
            for (int from = input.size() - 1; from >= 0; from--) {
                if (adHoc(input, from)) {
                    System.out.println(from);
                    break;
                }
            }
        }

    }

    private static String generateNs(int n) {
        StringBuilder b = new StringBuilder();
        Random rand = new Random(164134134374437674L);
        for (int i = 0; i < n; i++) {
            if (n != 0) {
                b.append(' ');
            }
            b.append(rand.nextInt(n));
        }
        return b.toString();
    }

    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 boolean adHoc(List<Integer> input, 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 : possibilities(input, at)) {
                if (!visited.contains(to)) {
                    q.add(to);
                }
            }

        }
        return false;
    }

    private static List<Integer> possibilities(List<Integer> in, int from) {
        List<Integer> moves = new ArrayList<>();
        for (int to = 0; to < in.size(); to++) {
            if (Math.abs(to - from) == in.get(from) + in.get(to)) {
                moves.add(to);
            }
        }
        return moves;
    }

    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;
    }

}