#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> s;
  int ans = 1, boz = 0, now = 1, cnt = 0;
  for (int i = 1; i < s.length(); i++)
    if (s[i] != s[i - 1])
      ans++, boz = max(boz, now), now = 1;
    else
      now++;
  boz = max(boz, now), now = 1;
  for (int i = 1; i < s.length(); i++)
    if (s[i] != s[i - 1]) {
      if (now == boz) cnt++;
      now = 1;
    } else
      now++;
  if (now == boz) cnt++;
  if ((boz == 2 && cnt > 1) || (boz > 2))
    cout << ans + 2 << endl;
  else if (boz == 2 and cnt == 1)
    cout << ans + 1 << endl;
  else if (boz == 1)
    cout << ans << endl;
  return 0;
}
