#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int last0 = 0;
  int last1 = 0;
  int qntp = 0;
  char x;
  char prev;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    if (x == '0') {
      last0 = max(last0, last1 + 1);
    }
    if (x == '1') {
      last1 = max(last1, last0 + 1);
    }
    if (i) {
      if (prev == x) {
        ++qntp;
      }
    }
    prev = x;
  }
  cout << max(last0, last1) + min(2, qntp);
  return 0;
}
