#include <bits/stdc++.h>
using namespace std;
int N;
char buf[100010];
int dp[100010][2][10];
int main(void) {
  int i, j, k;
  cin >> N;
  scanf("%s", buf);
  for ((i) = 0; (i) < (int)(N + 1); (i)++)
    for ((j) = 0; (j) < (int)(2); (j)++)
      for ((k) = 0; (k) < (int)(3); (k)++) dp[i][j][k] = -(1 << 29);
  dp[0][0][0] = dp[0][1][0] = 0;
  for ((i) = 0; (i) < (int)(N); (i)++)
    for ((j) = 0; (j) < (int)(2); (j)++)
      for ((k) = 0; (k) < (int)(3); (k)++)
        if (dp[i][j][k] != -(1 << 29)) {
          dp[i + 1][j][k] = max(dp[i + 1][j][k], dp[i][j][k]);
          int i2 = i + 1;
          int j2 = buf[i] - '0';
          int k2 = k + ((j != j2) ? 0 : 1);
          if (k2 <= 2) dp[i2][j2][k2] = max(dp[i2][j2][k2], dp[i][j][k] + 1);
        }
  int ans = 0;
  for ((i) = 0; (i) < (int)(2); (i)++)
    for ((j) = 0; (j) < (int)(3); (j)++) ans = max(ans, dp[N][i][j]);
  cout << ans << endl;
  return 0;
}
