#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int frames[N];
  for (int num = 0; num < N; num++) {
    cin >> frames[N];
  }
  double ave = 0;
  for (int num = 0; num < N; num++) {
    ave += frames[num];
  }
  ave = ave / N;
  int ans = INT16_MAX;
  for (int num = N; 0 < num; num--) {
    if (ans <= frames[num] - num) ans = num;
  }
  cout << --ans;
  return 0;
}
