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