#include <bits/stdc++.h>
using namespace std;
bool r = 1;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, mx = -1, m = -1, c = 0, f = 0, F = 0, mn = 100001;
  cin >> n;
  long long a[n];
  for (long long i = 0; i < n; i++) cin >> a[i];
  for (long long i = 0; i < n; i++) {
    if (mn >= a[i]) {
      mn = a[i];
      f = i;
    }
    if (mx <= a[i]) {
      mx = a[i];
      F = i;
    }
    if ((mx - mn) > 1) {
      i = min(f, F);
      mn = 100001;
      mx = -1;
      c = 0;
    } else
      c++;
    m = max(m, c);
  }
  cout << m << endl;
}
