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