#include <bits/stdc++.h>
using namespace std;
int a[1000050], num, ans;
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> num;
    a[num]++;
    a[num + 1]++;
    a[num - 1] = 0;
    a[num + 2] = 0;
    ans = max(ans, a[num]);
    ans = max(ans, a[num + 1]);
  }
  cout << ans << "\n";
}
