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