#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int L[n + 1];
  L[0] = 0;
  for (int i = 1; i < n + 1; i++) {
    cin >> L[i];
  }
  for (int i = 0; i < n + 1; i++) {
    if (L[i + 1] > L[i]) {
      L[i + 1] = L[i] + 1;
    } else {
      L[i + 1] = L[i];
    }
  }
  cout << L[n] << "\n";
}
