#include <bits/stdc++.h>
using namespace std;
int count(char str[]) {
  int start = 0;
  char last;
  last = str[0];
  start = 1;
  for (int i = 1; i < strlen(str); i++) {
    if (str[i] != last) {
      last = str[i];
      start++;
    }
  }
  return start;
}
char flip(char a) {
  if (a == '1') return '0';
  if (a == '0') return '1';
}
int main() {
  int n;
  scanf("%d", &n);
  char str[200005];
  scanf("%s", &str);
  int i, j;
  i = 1;
  j = n - 2;
  int s1, s2;
  s1 = -1;
  s2 = -1;
  printf("%d\n", min(2 + count(str), n));
}
