#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
multiset<int> s;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  int l = 0, r = 0, ans = 1;
  while (r < n) {
    s.insert(a[r]);
    while (*s.rbegin() - *s.begin() > 1) s.erase(s.find(a[l++]));
    ans = max(ans, (int)s.size());
    ++r;
  }
  printf("%d\n", ans);
  return 0;
}
