#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int dp[N][3][2];
string a;
int n;
int solve(int x, int state, int start) {
  if (x >= n) return 0;
  if (dp[x][state][start] != -1) return dp[x][state][start];
  int res = 0;
  if (state == 0) {
    if (start == a[x])
      res = max(solve(x + 1, 0, 1 - start) + 1, solve(x + 1, 1, start));
    else
      res = max(solve(x + 1, 1, 1 - start) + 1, solve(x + 1, 0, start));
  }
  if (state == 1) {
    if (start == a[x])
      res = max(solve(x + 1, 2, 1 - start) + 1, solve(x + 1, 1, start));
    else
      res = max(solve(x + 1, 2, start), solve(x + 1, 1, 1 - start) + 1);
  }
  if (state == 2) {
    if (start == a[x])
      res = solve(x + 1, 2, 1 - start) + 1;
    else
      res = solve(x + 1, 2, start);
  }
  dp[x][state][start] = res;
  return res;
}
int main() {
  std::ios::sync_with_stdio(false);
  ;
  cin >> n;
  memset((dp), (-1), sizeof(dp));
  cin >> a;
  for (int i = 0; i < n; i++) a[i] -= '0';
  cout << solve(0, 0, a[0]) << "\n";
  return 0;
}
