#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int best = 1;
  char last = s[0];
  for (int i = 1; i < n; i++)
    if (s[i] != last) {
      best += 1;
      last = s[i];
    }
  int cnt = 0;
  for (int i = 0; i < n - 1; i++)
    if (s[i] == s[i + 1]) cnt += 1;
  cout << best + min(2, cnt) << endl;
}
