#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int test = 1;
  while (test--) {
    int n;
    string s;
    cin >> n >> s;
    int b = s[0] - '0';
    int cnt = 1;
    for (int i = 1; i < n; i++) {
      if (s[i] != s[i - 1]) {
        cnt++;
        b = 1 - b;
      }
    }
    cout << ((n > cnt + 2) ? cnt + 2 : n) << endl;
  }
  return 0;
}
