#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int64_t n;
  cin >> n;
  string s;
  cin >> s;
  vector<int64_t> runs;
  char last = s[0];
  int64_t curr = 1;
  int64_t run2 = 0;
  for (int64_t i = 1; i < n; i++) {
    if (s[i] == last) {
      curr++;
    } else {
      if (curr == 2) run2++;
      runs.push_back(curr);
      curr = 1;
      last = s[i];
    }
  }
  if (curr == 2) run2++;
  runs.push_back(curr);
  for (int64_t i = 0; i < runs.size(); i++) {
    if (runs[i] > 2) {
      cout << runs.size() + 2 << endl;
      return 0;
    }
  }
  if (run2 == 0) {
    cout << n << endl;
  } else if (run2 == 1) {
    cout << runs.size() + 1 << endl;
  } else {
    cout << runs.size() + 2 << endl;
  }
  return 0;
}
