#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, t = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') t = -1;
    c = getchar();
  }
  while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
  return s * t;
}
const int N = 1e5 + 5;
int n, now, pre, c1, c2, c3, ans, f;
char c[N];
int main() {
  n = read();
  scanf("%s", c + 1);
  now = c[1] - '0', c1 = 1, c2 = 0, ans = 1;
  for (register int i = 2; i <= n; ++i) {
    if (c[i] - '0' != now)
      ans++, now ^= 1, c2 = c1, c1 = 1;
    else
      c1++;
    if (c1 > 2) f = 2;
    if (c2 >= 2 && c1 >= 2) f = 2;
    if (c1 == 2) c3++;
  }
  if (ans == n)
    cout << ans << endl;
  else if (f)
    cout << ans + f << endl;
  else if (c3 >= 2)
    cout << ans + 2 << endl;
  else
    cout << ans + 1 << endl;
  return 0;
}
