#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  string s;
  int n;
  cin >> n >> s;
  int e0 = 0, e1 = 0;
  bool b0 = true, b1 = true;
  for (int i = 0; i < n; i++) {
    if ((b0 && s[i] == '0') || (!b0 && s[i] == '1')) {
      b0 = !b0;
      e0++;
    }
    if ((b1 && s[i] == '1') || (!b1 && s[i] == '0')) {
      b1 = !b1;
      e1++;
    }
  }
  cout << min(n, max(e1, e0) + 2) << '\n';
}
