#include <bits/stdc++.h>
using namespace std;
int n;
char str[500010];
int main() {
  while (~scanf("%d%s", &n, str)) {
    if (n <= 3) {
      printf("%d\n", n);
      continue;
    }
    int flag = 0, cnt = 0, cou = 0;
    for (int i = 0; i < n;) {
      int re = i;
      while (i < n && str[re] == str[i]) {
        i++;
      }
      cnt++;
      if (flag) {
        continue;
      }
      if (i - re > 2) {
        cnt += 2;
        flag = 1;
      } else if (i - re == 2) {
        if (cou > 0) {
          cnt += 2;
          flag = 1;
        }
        cou = 2;
      }
    }
    if (!flag && cou) {
      cnt++;
    }
    printf("%d\n", cnt);
  }
  return 0;
}
