#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, r = 0, j, f = 0, g = 0;
  scanf("%d", &n);
  char c[100010];
  scanf("%s", c);
  for (i = 0; i < n;) {
    r++;
    char v = c[i];
    j = i;
    while (i < n && c[i] == v) ++i;
    if (i - j >= 3)
      g = 2;
    else if (g < 2 && i - j == 2) {
      if (f)
        g = 2;
      else {
        g = 1;
        f = 1;
      }
    }
  }
  printf("%d\n", r + g);
}
