#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int ans1 = 0, ans2 = 0, ans3 = 0;
  if (a[1] == 1) {
    ans1 = 1;
    for (int i = 2; i <= n; i++) {
      if (a[i] - a[i - 1] == 1)
        ans1++;
      else
        break;
    }
    ans1--;
  }
  if (a[n] == 1000) {
    ans3 = 1;
    for (int i = n - 1; i >= 1; i--) {
      if (a[i + 1] - a[i] == 1)
        ans3++;
      else
        break;
    }
    ans3--;
  }
  int cnt = 1;
  for (int i = 1; i <= n - 1; i++) {
    if (a[i + 1] - a[i] == 1)
      cnt++;
    else {
      ans2 = max(ans2, cnt);
      cnt = 1;
    }
  }
  ans2 = max(ans2, cnt);
  ans2 -= 2;
  cout << max(ans1, max(ans2, ans3));
}
