#include <bits/stdc++.h>
using namespace std;
int main() {
  int i, j, k = 1, l = 0, m = 0, n, p = 1;
  cin >> n;
  int ara[n];
  for (i = 0; i < n; i++) cin >> ara[i];
  if (n == 1)
    cout << 0 << endl;
  else {
    for (i = 0; i < n - 1; i++) {
      if (ara[i + 1] - ara[i] == 1) {
        k++;
        p = i + 1;
      } else {
        if (k > l) {
          l = k;
          m = p;
        } else if (k == l && ara[m - l - 1] != 1) {
          l = k;
          m = p;
        }
        k = 1;
      }
    }
    if (k > l) {
      l = k;
      m = p;
    } else if (k == l && ara[(m + 1) - l] != 1) {
      l = k;
      m = p;
    }
    m++;
    if ((l < 3 && ara[m - l] != 1 && ara[m - 1] != 1000))
      cout << 0 << endl;
    else {
      if ((m - l != 0 && ara[m - 1] != 1000 && ara[m - l] != 1 && n != 2) ||
          (ara[m - l] != 1 && ara[m - 1] != 1000 && m - l == 0 && n != 2))
        cout << l - 2 << endl;
      else
        cout << l - 1 << endl;
    }
  }
  return 0;
}
