#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  char a, b;
  cin >> a;
  long long int subs = 1;
  for (long long int i = 1; i < n; ++i) {
    cin >> b;
    if (a != b) {
      subs++;
      a = b;
    }
  }
  cout << min(n, subs + 2) << endl;
  return 0;
}
