#include <bits/stdc++.h>
using namespace std;
int N;
string S;
vector<int> occ;
int main() {
  ios::sync_with_stdio(0);
  cin >> N >> S;
  char last = S[0];
  int len = 1;
  for (int i = 1; i < N; i++) {
    if (S[i] == last)
      len++;
    else {
      occ.push_back(len);
      last = S[i];
      len = 1;
    }
  }
  occ.push_back(len);
  int ans = occ.size(), cnt2 = 0, cnt3 = 0;
  for (int i = 0; i < occ.size(); i++) {
    cnt2 += (occ[i] >= 2);
    cnt3 += (occ[i] >= 3);
  }
  if (cnt3 >= 1 || cnt2 > 1)
    ans += 2;
  else if (cnt2 == 1)
    ans++;
  cout << ans << "\n";
  return 0;
}
