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