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