#include <bits/stdc++.h>
using namespace std;
int main() {
  (ios_base::sync_with_stdio(false), cin.tie(NULL));
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < (int)(n); ++i) cin >> p[i];
  int l, r, mx, mn;
  l = r = 0;
  mn = mx = p[0];
  multiset<int> s;
  s.insert(p[0]);
  int ans = 1;
  while (r < n) {
    if (mx - mn <= 1) {
      ++r;
      if (r < n) s.insert(p[r]);
    } else {
      multiset<int>::iterator it = s.find(p[l]);
      s.erase(it);
      ++l;
    }
    mn = *(s.begin()), mx = *(s.rbegin());
    if (mx - mn <= 1 && r < n) ans = max(ans, r - l + 1);
  }
  cout << ans;
  getchar();
  getchar();
  return 0;
}
