#include <bits/stdc++.h>
using namespace std;
multiset<int> myset;
bool check(int x) {
  myset.insert(x);
  auto it = myset.end();
  it--;
  if (*it - *myset.begin() <= 1) return true;
  myset.erase(myset.find(x));
  return false;
}
int main() {
  int n, i;
  cin >> n;
  int ar[n + 1];
  for (i = 0; i < n; i++) cin >> ar[i];
  int l = 0, r = 0, ans = 0;
  while (r < n) {
    if (check(ar[r])) {
      int temp = myset.size();
      ans = max(ans, temp);
      r++;
    } else {
      myset.erase(myset.find(ar[l]));
      l++;
    }
  }
  cout << ans << endl;
}
