#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100100;
int n, p[MAXN], blocks, big, sol, bmax;
string s;
int main() {
  cin >> n;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (i == 0 || s[i] != s[i - 1])
      p[i] = 1;
    else
      p[i] = p[i - 1] + 1;
    if (p[i] == 1) {
      blocks++;
      if (i > 0 && p[i - 1] > 1) big++;
    }
    bmax = max(bmax, p[i]);
  }
  if (p[n - 1] > 1) big++;
  if (blocks == 1) {
    sol = 1;
    if (n >= 2) sol++;
    if (n >= 3) sol++;
  } else if (bmax >= 3)
    sol = blocks + 2;
  else
    sol = blocks + min(2, big);
  cout << sol << '\n';
}
