#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 123;
int N, ar[MAXN], dn[MAXN][2][2][2];
char s[MAXN];
int dfs(int w, int ever, int pre, int lt) {
  int &ret = dn[w][ever][pre][lt];
  if (w == N + 1) return 0;
  if (ret != -1) return ret;
  if (ever && !pre)
    return ret = dfs(w + 1, ever, pre, (!lt == ar[w]) ? ar[w] : lt) +
                 (!lt == ar[w]);
  ret = max(ret,
            dfs(w + 1, ever, 0, (!lt == ar[w]) ? ar[w] : lt) + (!lt == ar[w]));
  ret = max(ret, dfs(w + 1, 1, 1, (lt == ar[w]) ? !ar[w] : lt) + (lt == ar[w]));
  return ret;
}
int main() {
  scanf(" %d %s", &N, s + 1);
  for (int i = 1; i <= N; i++) ar[i] = s[i] - '0';
  memset(dn, -1, sizeof dn);
  int tmp1 = dfs(2, 0, 0, ar[1]) + 1;
  int tmp2 = dfs(2, 1, 1, !ar[1]) + 1;
  cout << max(tmp1, tmp2) << endl;
  return 0;
}
