#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, l = 0, ans = 0;
  cin >> n;
  vector<int> d(n, 0);
  for (int i = 0; i < n; i++) {
    cin >> d[i];
  }
  multiset<int> a;
  for (int i = 0; i < n; i++) {
    a.insert(d[i]);
    while (*a.rbegin() - *a.begin() > 1) {
      a.erase(a.find(d[l++]));
    }
    ans = max(ans, (int)a.size());
  }
  cout << ans;
  return 0;
}
