#include <bits/stdc++.h>
using namespace std;
const int maxm = 1e5 + 10;
int a[maxm];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    int i, j;
    int sum = 0;
    for (i = 0; i < n; i++) {
      scanf("%d", &a[i]);
    }
    for (i = 0; i < n; i++) {
      int Max = a[i];
      int Min = a[i];
      for (j = i + 1; j < n; j++) {
        if (a[j] > Max) {
          Max = a[j];
        }
        if (a[j] < Min) {
          Min = a[j];
        }
        if (Max - Min > 1) {
          break;
        }
      }
      int b = j - i;
      sum = max(sum, b);
      if (sum == n - i) {
        break;
      }
    }
    printf("%d\n", sum);
  }
  return 0;
}
