#include <bits/stdc++.h>
void read();
const int N = 1e5 + 100;
const int M = 2e5 + 100;
const long long oo = 1e18;
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n + 2);
  v[0] = 0;
  v[n + 1] = 1001;
  for (int i = 1; i <= n; i++) cin >> v[i];
  int ans = 0;
  int ma = 0;
  for (int i = 1; i <= n; i++) {
    if (abs(v[i] - v[i - 1]) == 1 && abs(v[i] - v[i + 1]) == 1)
      ans++;
    else
      ma = max(ma, ans), ans = 0;
  }
  ma = max(ma, ans), ans = 0;
  cout << ma;
  return 0;
}
void read() {
  freopen("in.txt", "r", stdin);
  freopen("ou.txt", "w", stdout);
}
