#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    string s;
    cin >> s;
    int res1 = 1;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] != s[i - 1]) res1++;
    }
    int res2 = 1;
    int r = 1;
    for (int i = 1; i < s.size(); i++) {
      if (s[i] != s[i - 1]) {
        r = max(r, res2);
      } else
        res2++;
    }
    r = max(r, res2);
    if (r == 1) r = 0;
    if (r == 2) r = 1;
    cout << res1 + min(2, r) << endl;
  }
  return 0;
}
