#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 100;
int n;
bool inp[MAXN];
int dp[MAXN][7];
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    char t;
    cin >> t;
    inp[i] = t - '0';
  }
  if (inp[0]) {
    dp[0][0] = 0;
    dp[0][1] = 1;
    dp[0][2] = 1;
    dp[0][3] = 0;
    dp[0][4] = 1;
    dp[0][5] = 0;
    dp[0][6] = 1;
  } else {
    dp[0][0] = 1;
    dp[0][1] = 0;
    dp[0][2] = 0;
    dp[0][3] = 1;
    dp[0][4] = 0;
    dp[0][5] = 1;
    dp[0][6] = 1;
  }
  for (int i = 1; i < n; i++) {
    if (inp[i]) {
      dp[i][1] = max(dp[i - 1][0] + 1, dp[i - 1][1]);
      dp[i][0] = dp[i - 1][0];
      dp[i][2] = max(max(dp[i - 1][3] + 1, dp[i - 1][1] + 1), dp[i - 1][2]);
      dp[i][3] = dp[i - 1][3];
      dp[i][4] = max(dp[i][2], dp[i - 1][4]);
      dp[i][5] = max(dp[i - 1][4] + 1, dp[i - 1][5]);
      for (int j = 0; j < 6; j++) dp[i][6] = max(dp[i][6], dp[i][j]);
    } else {
      dp[i][0] = max(dp[i - 1][1] + 1, dp[i - 1][0]);
      dp[i][1] = dp[i - 1][1];
      dp[i][2] = dp[i - 1][2];
      dp[i][3] = max(max(dp[i - 1][2] + 1, dp[i - 1][0] + 1), dp[i - 1][3]);
      dp[i][4] = max(dp[i - 1][5] + 1, dp[i - 1][4]);
      dp[i][5] = max(dp[i][3], dp[i - 1][5]);
      for (int j = 0; j < 6; j++) dp[i][6] = max(dp[i][6], dp[i][j]);
    }
  }
  cout << dp[n - 1][6] << endl;
  return 0;
}
