#include <bits/stdc++.h>
using namespace std;
int n, x = 1, y;
char s[100100];
int main(int argc, char **argv) {
  scanf("%d%s", &n, s);
  for (int i = 1; i < n; ++i) {
    x += s[i] != s[i - 1];
    y += s[i] == s[i - 1];
  }
  if (y >= 2)
    x += 2;
  else if (y == 1)
    ++x;
  printf("%d\n", x);
  return 0;
}
