#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, temp, ans = 0;
  cin >> n;
  map<int, int> m;
  while (n--) {
    cin >> temp;
    m[temp]++;
    m[temp + 1]++;
    m[temp - 1] = 0;
    m[temp + 2] = 0;
    ans = max({ans, m[temp], m[temp + 1]});
  }
  cout << ans;
}
