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

struct Node {
	int val;
	vector<int> points;
};
Node nodes[1000000];
array<bool,1000000> hits;

int main() {
	int k;
	while(cin >> k) {
		if(k==0) break;
		
		for(int i = 0; i<k; i++) {
			int m;
			cin >> m;
			nodes[i].val = m;
			nodes[i].points.clear();
			for(int l = 0; l<i; l++) {
				if(i-l == nodes[l].val+nodes[i].val) {
					nodes[i].points.push_back(l);
					nodes[l].points.push_back(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;
				for(int a : nodes[top].points) {
					if(!hits[a]) q.push(a);
				}
			}
		}
		cout << max << endl;
	}
	return 0;
}