#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  char tab[N];
  for (int i = 0; i < N; i++) cin >> tab[i];
  int dyn[N + 1][3][2];
  dyn[N][0][0] = dyn[N][1][0] = dyn[N][2][0] = 0;
  dyn[N][0][1] = dyn[N][1][1] = dyn[N][2][1] = 0;
  for (int i = N - 1; i >= 0; i--) {
    for (int j = 0; j <= 2; j++) {
      dyn[i][j][0] = dyn[i + 1][j][0];
      dyn[i][j][1] = dyn[i + 1][j][1];
    }
    for (int j = 0; j <= 2; j++) {
      if (tab[i] == '0')
        dyn[i][j][0] = max(dyn[i][j][0], dyn[i + 1][j][1] + 1);
      else
        dyn[i][j][1] = max(dyn[i][j][1], dyn[i + 1][j][0] + 1);
    }
    for (int j = 1; j <= 2; j++) {
      if (tab[i] == '0')
        dyn[i][j][0] = max(dyn[i][j][0], dyn[i + 1][j - 1][0] + 1);
      else
        dyn[i][j][1] = max(dyn[i][j][1], dyn[i + 1][j - 1][1] + 1);
    }
  }
  int result = 0;
  result = max(result, dyn[0][0][0]);
  result = max(result, dyn[0][1][0]);
  result = max(result, dyn[0][2][0]);
  result = max(result, dyn[0][0][1]);
  result = max(result, dyn[0][1][1]);
  result = max(result, dyn[0][2][1]);
  cout << result << endl;
}
