#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> seq(n, 0);
  transform(s.begin(), s.end(), seq.begin(),
            [](const char& c) { return int(c - '0'); });
  int score = 0;
  int cur = -1;
  int count = 0;
  bool p2 = false;
  bool p1 = false;
  int last = 0;
  vector<int> pat(2, 0);
  for (int i = 0; i < n; i++) {
    if (seq[i] != cur) {
      if (count >= 2 && last >= 2) p2 = true;
      last = count;
      cur = seq[i];
      count = 1;
      score++;
    } else {
      count++;
      if (count >= 3) p2 = true;
      if (count >= 2) {
        p1 = true;
        pat[cur]++;
      }
    }
  }
  if (count >= 2 && last >= 2) p2 = true;
  if (pat[0] >= 2 || pat[1] >= 2 || pat[0] + pat[1] >= 2) p2 = true;
  if (p2)
    cout << score + 2 << endl;
  else if (p1)
    cout << score + 1 << endl;
  else
    cout << score << endl;
  return 0;
}
