#include <bits/stdc++.h>
using namespace std;
struct IO {
  IO() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  }
} _;
int n, m, len, k, t, a, b;
int main() {
  string s;
  cin >> n >> s;
  char prev = s[0];
  int a = 0, b = 1;
  for (int i = 1; i <= n - 1; i++) {
    if (s[i] == s[i - 1]) a++;
    if (s[i] != prev) {
      prev = s[i];
      b++;
    }
  }
  b += min(a, 2);
  cout << b << "\n";
  return 0;
}
