#include <bits/stdc++.h>
using namespace std;
int tong[100005], a[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int j = 1, Max = 0, Min = 0x3f3f3f3f, ans = 0;
  for (int i = 1; i <= n; i++) {
    tong[a[i]]++;
    if (a[i] < Min) Min = a[i];
    if (a[i] > Max) Max = a[i];
    if (Max - Min > 1) {
      while (tong[Min] && tong[Max]) tong[a[j++]]--;
      if (!tong[Max]) Max--;
      if (!tong[Min]) Min++;
    }
    ans = max(ans, i - j + 1);
  }
  printf("%d\n", ans);
}
