#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  int ans = 0;
  int prev;
  if (s[0] == '0') prev = 1;
  if (s[0] == '1') prev = 0;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      if (prev == 1) ans++;
      prev = 0;
    }
    if (s[i] == '1') {
      if (prev == 0) ans++;
      prev = 1;
    }
  }
  cout << min(ans + 2, n) << endl;
  return 0;
}
