#include <bits/stdc++.h>
using namespace std;
int n, len, oo;
char s[100003];
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  len = 1;
  oo = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      oo++;
    else
      len++;
  }
  printf("%d\n", len + min(oo, 2));
}
