#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  int b[1001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    b[a[i]]++;
  }
  int max = 0, count = 1;
  for (int i = 1; i <= 999; i++) {
    if (b[i] == b[i + 1] && b[i] == 1) {
      count++;
    } else {
      if (count > max) {
        max = count;
      }
      count = 1;
    }
  }
  if (count != 1) {
    if (count > max) {
      max = count;
    }
    count = 1;
  }
  int count1 = 0, count2 = 0;
  for (int i = 1; i <= 1000; i++) {
    if (b[i] == 1) {
      count1++;
    } else {
      break;
    }
  }
  for (int i = 1000; i > 0; i--) {
    if (b[i] == 1) {
      count2++;
    } else {
      break;
    }
  }
  if (max == 1) {
    cout << "0"
         << "\n";
  } else if (max == count1 || max == count2) {
    cout << max - 1;
  } else {
    cout << max - 2 << "\n";
  }
}
