#include <iostream>
#include <vector>
#include <array>
#include <queue>
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);
		queue<int> q;
		q.push(0);
		int max = 0;
		while(!q.empty()) {
			if(!hits[q.front()]) {
				hits[q.front()] = true;
				if(q.front()>max) max = q.front();
				for(int a : nodes[q.front()].points) {
					if(!hits[a]) q.push(a);
				}
			}
			q.pop();
		}
		cout << max << endl;
	}
	return 0;
}