#include <bits/stdc++.h>
using namespace std;
const int IINF = INT_MAX;
int n;
string s;
inline char rev(char c) { return (c == '0') ? '1' : '0'; }
void compute() {
  vector<int> seq;
  for (int i = 0; i < (int)s.size(); i++) {
    int cnt = 0;
    char c = s[i];
    int sp = i;
    while (i < (int)s.size() && s[i] == c) ++cnt, ++i;
    --i;
    cnt = min(cnt, 3);
    seq.push_back(cnt);
  }
  int base = (int)seq.size();
  int two = 0;
  for (int i = 0; i < (int)seq.size(); i++)
    if (seq[i] >= 2) ++two;
  if (two >= 1) {
    cout << min(base + 2, n) << endl;
    return;
  }
  if (seq[0] >= 2 || seq[(int)seq.size() - 1] >= 2) {
    cout << base + 1 << endl;
    return;
  }
  cout << base << endl;
}
int main() {
  cin >> n >> s;
  compute();
  return 0;
}
