import java.io.*;
import java.util.*;

public class JB 
{
	public static void main(String [] args)
	{
		int [] vals = new int [101];
		int n;

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line ="";
		try {
			line = in.readLine();
		} catch (Exception e) {};
		StringTokenizer str = new StringTokenizer(line);
		n = Integer.parseInt(str.nextToken());
		while (n != 0) {
			for(int i=0; i<n; i++) {
				vals[n-i] = Integer.parseInt(str.nextToken());
			}
			int j=n-1;
			while (j > 0) {
				if (vals[j+1]-1 < vals[j])
					vals[j] = vals[j+1]-1;
				if (vals[j] == 0)
					break;
				j--;
			}
			System.out.println(j);

			try {
				line = in.readLine();
			} catch (Exception e) {};
			str = new StringTokenizer(line);
			n = Integer.parseInt(str.nextToken());
		}
	}
}
