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