#include <bits/stdc++.h>
char s[100010];
int n, bf, T;
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  char last = s[1];
  int cnt = 1, m = 1;
  for (int i = 2; i <= n; i++) {
    if (s[i] == last)
      cnt++;
    else {
      m++;
      if (cnt > 2)
        bf = 1;
      else if (cnt == 2)
        T++;
      cnt = 1;
      last = s[i];
    }
  }
  if (cnt > 2)
    bf = 1;
  else if (cnt == 2)
    T++;
  if (bf || T > 1)
    printf("%d\n", m + 2);
  else if (T == 1)
    printf("%d\n", m + 1);
  else
    printf("%d\n", m);
}
