#include <bits/stdc++.h>
using namespace std;
int n, ok, cnt;
char last;
string str;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n >> str;
  for (int i = 0; i < n; i++) {
    if (str[i] != last) cnt++, last = str[i];
    if (i && str[i] == str[i - 1]) ok = 1;
  }
  cout << min(cnt + 2, n) << endl;
  return 0;
}
