#include <bits/stdc++.h>
int main() {
  int i, n, df = 0, eq = 0;
  char s[100000 + 1];
  scanf("%d\n", &n);
  gets(s);
  for (i = 1; i < n; i++) s[i] == s[i - 1] ? eq++ : df++;
  df++;
  if (eq > 1)
    df += 2;
  else if (eq == 1)
    df++;
  printf("%d", df);
  return 0;
}
