#include <bits/stdc++.h>
using namespace std;
map<int, int> mp;
int main() {
  int n, ad = 0, ans = 0;
  string s;
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (i == 0) {
      ans = 1;
      continue;
    }
    if (s[i] != s[i - 1])
      ans++;
    else
      ad++;
  }
  ad = min(ad, 2);
  cout << ans + ad << endl;
  return 0;
}
