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