#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <sstream>
using namespace std;

#define DEBUG(x) cout << ">" << #x << ": " << x << endl

void f(int cur, const vector<int> & list, map<int,int> & options, int & best) {
	options.erase(cur);
	for ( auto option : options )
	{
		if ( abs(cur-option.first) != list[cur]+option.second )
			continue;
		if ( option.first == list.size()-1 )
		{
			best = list.size()-1;
			return;
		}
		best = max(best, option.first);
		f(option.first, list, options, best);
	}
}

int main() {
int N;
for ( ;; ) {
	vector<int> list;
	map<int,int> options;

	cin >> N;

	if ( !N )
		break;

	string line;
	cin.ignore();
	getline(cin, line);
	istringstream is(line);

	for ( int i = 0 ; i < N ; ++i )
	{
		int x;
		is >> x;
		list.push_back(x);
		options.insert(make_pair(i, x));
	}
	int best = 0;
	f(0, list, options, best);
	cout << best << endl;
}
return 0;
}