#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n, arr[N];
map<long long, long long> mp;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> arr[i];
  long long lower = 1, upper = 1, ans = 1;
  while (upper <= n) {
    long long now = arr[upper];
    mp[now]++;
    if ((*(mp.rbegin())).first - (*(mp.begin())).first <= 1) {
      ans = max(ans, upper - lower + 1);
    } else {
      while ((*(mp.rbegin())).first - (*(mp.begin())).first > 1) {
        mp[arr[lower]]--;
        if (mp[arr[lower]] == 0) {
          mp.erase(arr[lower]);
        }
        lower++;
      }
      ans = max(ans, upper - lower + 1);
    }
    upper++;
  }
  cout << ans << endl;
}
