#include <iostream>
#include <vector>
#include <array>
#include <stack>
using namespace std;


int nodes[1000000];
array<bool,1000000> hits;

int main() {
	int k;
	while(cin >> k) {
		if(k==0) break;
		
		for(int i = 0; i<k; i++) {
			cin >> nodes[i];
		}
		hits.fill(false);
		stack<int> q;
		q.push(0);
		int max = 0;
		while(!q.empty()) {
			int top = q.top();
			q.pop();
			if(!hits[top]) {
				hits[top] = true;
				if(top>max) {
					max = top;
					if(max == k-1) break;
				}
				for(int l = 0; l<=top-nodes[top]; l++) {
					if(!hits[l] && abs(top-l) == nodes[l]+nodes[top]) {
						q.push(l);
					}
				}

				for(int l = top+nodes[top]; l<k; l++) {
					if(!hits[l] && abs(top-l) == nodes[l]+nodes[top]) {
						q.push(l);
					}
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}