#include <bits/stdc++.h>
using namespace std;
int seq[100000 + 10 + 10];
int vis[100000 + 10];
int n;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> seq[i];
  }
  int i = 0, j = 0;
  int dif = 0;
  int cmin = seq[i], cmax = seq[i];
  vis[seq[i]]++;
  int ml = 0;
  while (i <= j && j < n) {
    if (dif < 2) {
      ml = max(ml, j - i + 1);
      j++;
      vis[seq[j]]++;
      cmin = min(cmin, seq[j]);
      cmax = max(cmax, seq[j]);
      dif = cmax - cmin;
    } else {
      vis[seq[i]]--;
      if (seq[i] == cmin) cmin = (vis[seq[i]] >= 1) ? seq[i] : seq[i] + 1;
      if (seq[i] == cmax) cmax = (vis[seq[i]] >= 1) ? seq[i] : seq[i] - 1;
      dif = cmax - cmin;
      i++;
    }
  }
  cout << ml << endl;
  return 0;
}
