#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > sequencia;
int main() {
  int TC;
  int n;
  int ans = 0;
  scanf("%d", &TC);
  scanf("%d", &n);
  sequencia.push_back({n, 1});
  for (int i = 1; i < TC; ++i) {
    scanf("%d", &n);
    if (n == sequencia[(int)sequencia.size() - 1].first)
      ++sequencia[(int)sequencia.size() - 1].second;
    else
      sequencia.push_back({n, 1});
  }
  if (0)
    for (auto p : sequencia) cout << p.first << " " << p.second << endl;
  int idx = 0;
  pair<int, int> value;
  while (idx < sequencia.size()) {
    ans = max(sequencia[idx].second, ans);
    int s = 0, new_idx;
    if (abs(sequencia[idx].first - sequencia[idx + 1].first) <= 1) {
      value.first = sequencia[idx].first;
      value.second = sequencia[idx + 1].first;
      new_idx = idx;
      while (sequencia[new_idx].first == value.first ||
             sequencia[new_idx].first == value.second &&
                 new_idx < sequencia.size()) {
        s += sequencia[new_idx].second;
        ++new_idx;
      }
      if (0) cout << "S: " << s << endl;
      if (new_idx - idx == 1)
        idx++;
      else
        idx = new_idx - 1;
      ans = max(ans, s);
      if (0) cout << "NOVO IDX:" << idx << endl;
    } else
      idx++;
  }
  printf("%d\n", ans);
  return 0;
}
