#include <bits/stdc++.h>
using namespace std;
long long poww(long long x, long long y) {
  if (y == 0) return 1;
  long long second = poww(x, y / 2);
  second = (second * second);
  if (y % 2 == 1) second = (second * x);
  return second;
}
multiset<int> second;
vector<int> v;
bool ok() {
  return (second.size() == 0) || (abs(*second.rbegin() - *second.begin()) <= 1);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  int l = 0, r = 0, ma = -1;
  while (r <= n) {
    while (r <= n && ok()) {
      second.insert(v[r]);
      r++;
    }
    ma = max(ma, r - l - 1);
    while (l < n && !ok()) {
      second.erase(second.find(v[l]));
      l++;
    }
  }
  cout << ma;
  return 0;
}
