#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const* argv[]) {
  int n;
  string s;
  cin >> n >> s;
  int count = 3;
  for (int i = 1; i < n; i += 1) {
    count += (s[i] != s[i - 1]);
  }
  if (count > n) count = n;
  cout << count << endl;
  return 0;
}
