#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, c = 0, i, ans = 0;
  scanf("%d", &n);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  for (i = 0; i < n; i++) {
    if (i == 0) {
      if (a[1] == 2) {
        c++;
      }
    } else if (i == n - 1 && a[n - 2] == 999) {
      c++;
    } else if (a[i] == a[i - 1] + 1 && a[i] == a[i + 1] - 1 && i != n - 1) {
      c++;
    } else {
      ans = max(ans, c);
      c = 0;
    }
  }
  ans = max(ans, c);
  cout << ans;
}
