#include <bits/stdc++.h>
using namespace std;
long long int arr[1000000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  arr[n] = 999999999;
  int fr = 0;
  int sc = 0;
  int mini = arr[0];
  int maxi = arr[0];
  int ans = 1;
  for (int i = 1; i < n + 1; i++) {
    sc = i;
    if (arr[i] < mini) mini = arr[i];
    if (arr[i] > maxi) maxi = arr[i];
    if (abs(maxi - mini) > 1) {
      mini = 999999999;
      maxi = -999999999;
      ans = max(ans, sc - fr);
      int j;
      for (j = sc; j >= 0; j--) {
        if (abs(arr[j] - arr[i]) > 1) break;
        fr = j;
        if (arr[j] < mini) mini = arr[j];
        if (arr[j] > maxi) maxi = arr[j];
      }
    }
  }
  cout << ans << endl;
}
