#include <bits/stdc++.h>
using namespace std;
string v;
int dp[2][3][100010], n;
int main() {
  ios::sync_with_stdio(false);
  while (cin >> n >> v) {
    for (int a = (0); a < (2); a++)
      for (int j = (0); j < (3); j++) dp[a][j][n] = 0;
    for (int i = n - 1; i >= 0; i--) {
      for (int j = (0); j < (3); j++) {
        bool act = (j == 1 ? !(v[i] - '0') : (v[i] - '0'));
        dp[!act][j][i] = max(dp[act][j][i + 1] + 1, dp[!act][j][i + 1]);
        dp[act][j][i] = dp[act][j][i + 1];
        if (j != 2)
          dp[act][j][i] = max(dp[act][j][i], dp[!act][j + 1][i + 1] + 1);
      }
    }
    cout << dp[!(v[0] - '0')][0][0] << endl;
  }
  return 0;
}
