#include <bits/stdc++.h>
using namespace std;
int n, two, r, now, ans, l;
char c[1000005];
bool three;
int main() {
  scanf("%d ", &n);
  gets(c);
  now = '1' + '0' - c[0];
  for (int i = 0; i < n; i++) {
    if (c[i] == now) {
      r++;
    } else {
      now = '1' + '0' - now;
      r = 1;
      ans++;
    }
    if (r == 2) {
      two++;
      l = i;
    }
    if (r == 3) three = 1;
  }
  if (two > 1 || three)
    ans += 2;
  else if (two == 1)
    ans += 1;
  printf("%d", ans);
}
