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