#include <bits/stdc++.h>
using namespace std;
int n, arr[100005], num[100005];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  memset(num, 0, sizeof(num));
  num[arr[0]] = 1;
  int l = 0, r = 1;
  int rg = 0;
  for (l = 0, r = 1; r < n; r++) {
    if (num[arr[r] - 2] == 0 && num[arr[r] + 2] == 0) {
      num[arr[r]]++;
    } else {
      num[arr[l]]--;
      l++;
      r--;
    }
    if (r - l + 1 > rg) rg = r - l + 1;
  }
  cout << rg << endl;
  return 0;
}
