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