#include <bits/stdc++.h>
using namespace std;
char str[100020];
int len[3] = {0};
int num[100020];
void zhuanhuan(int x) {
  if (x >= 3) {
    len[2]++;
  } else if (x == 2) {
    len[1]++;
  } else {
    len[0]++;
  }
}
int main() {
  int n, kuan = 1;
  scanf("%d", &n);
  scanf("%*c");
  for (int i = 0; i < n; i = i + 1) scanf("%c", &str[i]);
  scanf("%*c");
  for (int i = 0; i < n; i = i + 1) num[i] = str[i] - '0';
  int kuanlen = 1;
  for (int i = 1; i < n; i++) {
    if (num[i] == num[i - 1]) {
      kuanlen++;
    } else {
      kuan++;
      zhuanhuan(kuanlen);
      kuanlen = 1;
    }
  }
  zhuanhuan(kuanlen);
  if (len[2] > 0) {
    printf("%d\n", kuan + 2);
  } else if (len[1] > 1) {
    printf("%d\n", kuan + 2);
  } else {
    if (len[1] == 1)
      printf("%d\n", kuan + 1);
    else
      printf("%d\n", kuan);
  }
  return 0;
}
