#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n;
char s[maxn];
int ret;
int main() {
  scanf("%d", &n);
  scanf("%s", s);
  ret = 3;
  for (int i = (1); i < (n); i++) ret += (s[i] != s[i - 1]);
  if (ret > n) ret = n;
  printf("%d\n", ret);
  return 0;
}
