#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 5;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ;
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  long long int maxso = 2, maxi = 1;
  long long int mn, id1, mx, id2;
  mx = mn = a[0];
  id1 = id2 = 0;
  long long int i, j = 0;
  for (i = 1; i < n; i++) {
    if (a[i] <= mn) {
      mn = a[i];
      id1 = i;
    }
    if (a[i] >= mx) {
      mx = a[i];
      id2 = i;
    }
    if ((mx - mn) > 1) {
      if (mx == a[i])
        i = id1 + 1;
      else
        i = id2 + 1;
      j = i;
      mn = mx = a[i];
      id1 = id2 = i;
    } else {
      maxso = max(maxso, (i - j + 1));
    }
  }
  cout << maxso << endl;
  return 0;
}
