#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, AMin, AMax, m = 1, t = 0;
  cin >> n;
  int A[n], S[100001];
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < 100001; i++) {
    S[i] = 0;
  }
  AMin = A[0];
  AMax = A[0];
  S[A[0]]++;
  for (int i = 1; i < n; i++) {
    if (A[i] < AMin) {
      AMin = A[i];
    }
    if (A[i] > AMax) {
      AMax = A[i];
    }
    S[A[i]]++;
    while (AMax - AMin > 1) {
      if (A[t] == AMin && S[A[t]] == 1) {
        AMin++;
      }
      if (A[t] == AMax && S[A[t]] == 1) {
        AMax--;
      }
      S[A[t]]--;
      t++;
    }
    m = max(m, i - t + 1);
  }
  cout << m;
  return 0;
}
