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