#include <bits/stdc++.h>
using namespace std;
char s[1000001];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s);
  int bf1 = 0, bf2 = 0, ans = 0, len = 1;
  for (int i = 1; i <= n; i++) {
    if (s[i] != s[i - 1]) {
      if (len >= 3)
        bf2 = 1;
      else if (len >= 2)
        bf1++;
      len = 1;
      ans++;
    } else
      len++;
  }
  if (bf2 || bf1 >= 2)
    printf("%d\n", ans + 2);
  else if (bf1)
    printf("%d\n", ans + 1);
  else
    printf("%d\n", ans);
}
