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