#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long n, i, x = 0, c = 1;
  cin >> n;
  string s;
  cin >> s;
  for (i = 1; i < s.size(); i++) {
    if (s[i - 1] != s[i]) c++;
  }
  cout << min(c + 2, n);
}
