#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j, c = 1, max = 0, min1, max1, posx, posy;
  cin >> n;
  int a[n];
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (i = 0; i < n; i++) {
    min1 = a[i];
    max1 = a[i];
    posx = i;
    posy = i;
    for (j = i + 1; j < n; j++) {
      if (max1 <= a[j]) {
        max1 = a[j];
        posx = j;
      }
      if (min1 >= a[j]) {
        min1 = a[j];
        posy = j;
      }
      if (max1 - min1 <= 1)
        c++;
      else
        break;
    }
    if (c > max) max = c;
    i = min(posx, posy);
    c = 1;
  }
  cout << max;
  return 0;
}
