#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    v.push_back(a);
  }
  int first = 0, res = 0;
  int i = 1;
  for (; i < n; ++i) {
    if (v[i] != v[i - 1] + 1) {
      if (v[first] == 1) {
        res = max(res, i - first - 1);
      } else if (i - first >= 2) {
        res = max(res, i - first - 2);
      }
      first = i;
    }
  }
  if (v[first] + (i - first) == 1001 || v[first] == 1) {
    res = max(res, i - first - 1);
  } else if (i - first >= 3) {
    res = max(res, i - first - 2);
  }
  cout << res << endl;
  return 0;
}
