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