#include<cstdio>
#include<vector>
using namespace std;

int n, a[100000];
vector<int> d;

int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  d.push_back(1);
  int size = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) d[size]++;
    else d.push_back(1), size++;
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    int sum = 0;
    for (int j = i; j <= size && j < i + 3; j++) sum += d[j];
    ans = max(ans, sum);
  }
  printf("%d\n", ans);
}

