#include <bits/stdc++.h>
int main() {
  int n, ans;
  char a[100000];
  scanf("%d", &n);
  scanf("%s", a);
  ans = 1;
  char cur = a[0];
  for (int i = 1; i < n; i++)
    if (a[i] != cur) {
      ans++;
      cur = a[i];
    }
  if (ans >= n - 1)
    ans = n;
  else
    ans += 2;
  printf("%d\n", ans);
  return 0;
}
