#include <bits/stdc++.h>
using namespace std;
int arr[100005];
bool fun(int arr[], int i, int j) {
  for (int k = i + 1; k <= j; k++) {
    if (arr[k] != arr[k - 1] + 1) return false;
  }
  return true;
}
int ans = 0;
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (fun(arr, i, j)) {
        int count = j - i - 1;
        if (arr[i] == 1)
          count++;
        else if (arr[j] == 1000)
          count++;
        ans = max(ans, count);
      }
    }
  }
  cout << ans << endl;
}
