#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, ans(0), c(0);
  cin >> n;
  long long arr[n];
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (n == 1) return cout << 0, 0;
  for (long long i = 0; i < n - 1; i++) {
    if (arr[i + 1] == arr[i] + 1) {
      c++;
    } else {
      c++;
      ans = max(ans, c);
      c = 0;
    }
  }
  if (arr[n - 1] == arr[n - 2] + 1) c++;
  ans = max(ans, c);
  if (ans == n and (arr[0] == 1 or arr[n - 1] == 1000))
    ans = ans - 1;
  else
    ans = ans - 2;
  if (arr[n - 1] == 1000) {
    long long i = n - 1, c1(0);
    while (i - 1 >= 0 and arr[i] == arr[i - 1] + 1) {
      c1++;
      i--;
    }
    c1++;
    ans = max(ans, c1 - 1);
  }
  if (arr[0] == 1) {
    long long i = 0, c2(0);
    while (i + 1 < n and arr[i + 1] == arr[i] + 1) {
      c2++;
      i++;
    }
    c2++;
    ans = max(ans, c2 - 1);
  }
  if (ans < 0) ans = 0;
  cout << ans;
  return 0;
}
