#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int r = 0, max_len = 1, max_ind = 0, min_ind = 0;
  for (int l = 0; l < n; l++) {
    while (r < n && a[max_ind] - a[min_ind] < 2) {
      if (a[r] >= a[max_ind]) {
        max_ind = r;
      }
      if (a[r] <= a[min_ind]) {
        min_ind = r;
      }
      if (r < n && a[max_ind] - a[min_ind] < 2) {
        r++;
      }
    }
    max_len = max(max_len, r - l);
    if (max_ind == l) {
      max_ind++;
    }
    if (min_ind == l) {
      min_ind++;
    }
  }
  cout << max_len;
  return 0;
}
