#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
void qread(int &x) {
  int neg = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = 10 * x + c - '0', c = getchar();
  x *= neg;
}
const int maxn = 100005;
int n;
char c[maxn];
int dp[maxn][2][3];
int main() {
  scanf("%d%s", &n, c);
  memset(dp, -1, sizeof(dp));
  dp[0][0][0] = dp[0][1][0] = 0;
  for (int(i) = 0; (i) < n; i++)
    for (int(j) = 0; (j) < 2; j++)
      for (int(k) = 0; (k) < 3; k++) {
        int cur = dp[i][j][k];
        if (cur < 0) continue;
        dp[i + 1][j][k] = max(dp[i + 1][j][k], cur);
        if (c[i] - '0' != j)
          dp[i + 1][c[i] - '0'][k] = max(dp[i + 1][c[i] - '0'][k], cur + 1);
        else if (k < 2)
          dp[i + 1][c[i] - '0'][k + 1] =
              max(dp[i + 1][c[i] - '0'][k + 1], cur + 1);
      }
  int ans = 0;
  for (int(j) = 0; (j) < 2; j++)
    for (int(k) = 0; (k) < 3; k++) ans = max(ans, dp[n][j][k]);
  printf("%d", ans);
  return 0;
}
