#include <bits/stdc++.h>
using namespace std;
int las(string k) {
  int n = k.size();
  vector<int> vc(n);
  vc[0] = 1;
  for (int i = 1; i < n; i++) {
    if (k[i] != k[i - 1])
      vc[i] = vc[i - 1] + 1;
    else
      vc[i] = vc[i - 1];
  }
  return vc[n - 1];
}
int main() {
  int n;
  cin >> n;
  string k;
  cin >> k;
  cout << min(las(k) + 2, n);
}
