#include <bits/stdc++.h>
using namespace std;
char cc;
void read(int &x) {
  cc = getchar();
  for (; cc < '0' || cc > '9'; cc = getchar())
    ;
  for (x = 0; cc >= '0' && cc <= '9'; cc = getchar()) x = x * 10 + cc - '0';
}
int n;
char s[111111];
int main() {
  scanf("%d", &n);
  scanf(" ");
  gets(s + 1);
  int cnt = 0, res = 1;
  for (int i = 1; i < n; ++i) {
    cnt += (s[i] == s[i + 1]);
    if (s[i] != s[i + 1]) res++;
  }
  printf("%d\n", res + (((cnt) < (2)) ? (cnt) : (2)));
  return 0;
}
