#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100010;
char s[MAXN];
int main() {
  int n;
  scanf("%d%s", &n, s);
  int ans = 1, ins = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      ans++;
    else
      ins++;
  }
  printf("%d\n", ans + min(ins, 2));
  return 0;
}
