#include <bits/stdc++.h>
using namespace std;
const int inf = 17070509;
int n;
string S;
vector<int> A;
vector<vector<vector<int> > > memo;
int DP(int x, int state, int prev) {
  if (x == n)
    return 0;
  else if (memo[x][state][prev] != -1)
    return memo[x][state][prev];
  int res = 0;
  if (!x) {
    if (state == 0) {
      res = max(res, max(DP(x + 1, 0, A[0]), DP(x + 1, 1, !A[0])));
    } else if (state == 1) {
      res = max(res, max(DP(x + 1, 1, A[0]), DP(x + 1, 2, !A[0])));
    }
    res++;
  } else {
    if (state == 0) {
      res = max(res,
                max(DP(x + 1, 1, !prev), DP(x + 1, 1, !A[x]) + (A[x] != prev)));
      res = max(res,
                max(DP(x + 1, 0, prev), DP(x + 1, 0, A[x]) + (A[x] != prev)));
    } else if (state == 1) {
      res = max(res,
                max(DP(x + 1, 2, !prev), DP(x + 1, 2, !A[x]) + (A[x] != prev)));
      res = max(res,
                max(DP(x + 1, 1, prev), DP(x + 1, 1, A[x]) + (A[x] != prev)));
    } else {
      res = max(res,
                max(DP(x + 1, 2, prev), DP(x + 1, 2, A[x]) + (A[x] != prev)));
    }
  }
  memo[x][state][prev] = res;
  return res;
}
int main(void) {
  scanf("%d", &n);
  if (n == 1) {
    printf("1\n");
    return 0;
  }
  A.clear();
  A.resize(n);
  memo.clear();
  memo.resize(n + 5, vector<vector<int> >(4, vector<int>(3, -1)));
  cin >> S;
  for (int i = 0; i < n; i++) A[i] = int(S[i] - '0');
  int res = 0;
  res = max(DP(0, 0, A[0]), DP(0, 1, !A[0]));
  printf("%d\n", res);
}
