#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, cnt = 0, len;
  string s;
  cin >> n >> s;
  len = s.length() - 1;
  for (int i = 0; i < len; i++)
    if (s[i] != s[i + 1]) cnt++;
  if ((s.find("111") != -1) || (s.find("000") != -1))
    cnt += 2;
  else if ((s.find("00110") != -1) || (s.find("01100") != -1) ||
           (s.find("11001") != -1) || (s.find("10011") != -1))
    cnt += 2;
  else {
    int tmp = 0;
    for (int i = 0; i < len; i++) {
      if ((s[i] == '0' && s[i + 1] == '0') || (s[i] == '1' && s[i + 1] == '1'))
        tmp++;
      if (tmp == 2) break;
    }
    cnt += tmp;
  }
  cout << cnt + 1 << endl;
  return 0;
}
