#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long N;
  cin >> N;
  vector<long long> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  long long maxl = 0;
  for (long long i = 0; i < N; i++) {
    long long maxi = A[i];
    long long mini = A[i];
    long long count = 1;
    for (long long j = i + 1; j < N; j++) {
      maxi = max(maxi, A[j]);
      mini = min(mini, A[j]);
      if (maxi - mini > 1) break;
      count++;
    }
    maxl = max(maxl, count);
    if (maxl > (N / 2)) break;
  }
  cout << maxl << "\n";
  return 0;
}
