#include <bits/stdc++.h>
using namespace std;
int dp[1 << 17][3][2];
int s[1 << 17];
void solve(int i, int state) {
  if (i == 0) return;
  int &z = dp[i][state][0], &o = dp[i][state][1];
  if (z != -1) return;
  if (state == 0) {
    solve(i - 1, 0);
    if (s[i] == 1) {
      z = dp[i - 1][state][0];
      o = max(dp[i - 1][state][1], dp[i - 1][state][0] + 1);
    } else {
      o = dp[i - 1][state][1];
      z = max(dp[i - 1][state][0], dp[i - 1][state][1] + 1);
    }
    return;
  }
  if (state == 1) {
    solve(i - 1, 1);
    solve(i - 1, 0);
    if (s[i] == 1) {
      z = max(dp[i - 1][0][0], max(dp[i - 1][1][0], dp[i - 1][1][1] + 1));
      o = max(dp[i - 1][1][1], max(dp[i - 1][0][1], dp[i - 1][0][0] + 1));
    } else {
      o = max(dp[i - 1][0][1], max(dp[i - 1][1][1], dp[i - 1][1][0] + 1));
      z = max(dp[i - 1][1][0], max(dp[i - 1][0][0], dp[i - 1][0][1] + 1));
    }
    return;
  }
  solve(i - 1, 2);
  solve(i - 1, 1);
  if (s[i] == 1) {
    z = max(dp[i - 1][2][0], max(dp[i - 1][1][0], dp[i - 1][1][1] + 1));
    o = max(dp[i - 1][1][1], max(dp[i - 1][2][1], dp[i - 1][2][0] + 1));
  } else {
    o = max(dp[i - 1][2][1], max(dp[i - 1][1][1], dp[i - 1][1][0] + 1));
    z = max(dp[i - 1][1][0], max(dp[i - 1][2][0], dp[i - 1][2][1] + 1));
  }
  return;
}
int main() {
  int n;
  while (cin >> n) {
    memset(dp, -1, sizeof dp);
    for (int i = 0; i < 3; ++i) dp[0][i][0] = dp[0][i][1] = 0;
    for (int i = 1; i <= n; ++i) scanf("%1d", s + i);
    solve(n, 2);
    cout << max(dp[n][2][0], dp[n][2][1]) << endl;
  }
}
