/*
 * 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.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.TreeMap;

/**
 *
 * @author olesnanik2
 */
public class YoshiEffective {
    static public int pebbles;
    
    static public HashSet<Integer> minuses = new HashSet<>();
    static public HashSet<Integer> pluses = new HashSet<>();
    static public int[] spotsArray = new int[1000000];
    
    public static void main(String [] arguments) throws Exception {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        
        while(true) {
            pluses.clear();
            minuses.clear();
            
            pebbles = nextInt(reader);
            if (pebbles == 0) {
                break;
            }
            for (int p=0; p<pebbles; p++) {
                int spots = nextInt(reader);
                spotsArray[p] = spots;
                pluses.add(p+spots);
                minuses.add(p-spots);
            }
            
            Iterator<Integer> it = pluses.iterator();
            while(it.hasNext()) {
                if (!minuses.contains(-it.next())) {
                    it.remove();
                }
            }
            
            it = minuses.iterator();
            while(it.hasNext()) {
                if (!pluses.contains(it.next())) {
                    it.remove();
                }
            }
           
            if (!pluses.contains(spotsArray[0]) && !minuses.contains(-spotsArray[0])) {
                System.out.println("0");
            } else {
                for(int p=pebbles-1; p >= 0; p--) {
                    if (pluses.contains(p+spotsArray[p]) || minuses.contains(p-spotsArray[p])) {
                        System.out.println(p);
                        break;
                    }
                }
            }
        }
    }
    
    public static int nextInt(BufferedReader reader) throws Exception {
        int n = 0;
        char c;
        while(true) {
            c = (char)reader.read();
            if (c == 0 || c == ' ' || c == '\n') {
                return n;
            }
            n *= 10;
            n += c - '0';
        }
    }
}