#include <iostream>
#include <vector>
#include <stack>
#include <cmath>

typedef unsigned long long ull;
using namespace std;

int dfs(vector<ull> &S, int i)
{
  int N = S.size();
  vector<char> V(N);
  stack<int> D;
  D.push(i);
  V[i] = true;

  while (!D.empty()) {
    int d = D.top();
    D.pop();
    for (i = 0; i < N; ++i) {
      if (S[d] + S[i] == abs(d - i) &&
          V[i] == false) {
        D.push(i);
        V[i] = true;
      }
    }
  }
  for (i = N-1; i >= 0; --i)
    if (V[i]) return i;
  return -1;
}

int main() {
  ios_base::sync_with_stdio(false);
  int N;
  cin >> N;
  while (N != 0) {
    vector<ull> S(N);
    for (int i = 0; i < N; ++i)
      cin >> S[i];
    cout << dfs(S, 0) << "\n";

    cin >> N;
  }
  return 0;
}