#include <bits/stdc++.h>
using namespace std;
int a[100000];
int count(int base, int n, int size) {
  int mx = 0;
  for (int i = n; i < size; i++) {
    if (a[i] > base) {
      mx = max(mx, count(a[i], i, size));
    }
    if (a[i] == base + 1) {
      break;
    }
  }
  return mx;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  cout << count(-1, 0, n) << endl;
  return 0;
}
