#include <bits/stdc++.h>
using namespace std;
const long double pi = 3.1415926535897932384626433;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long ans = 1;
  for (long long i = 1; i < n; i++) {
    ans += (s[i] != s[i - 1]);
  }
  cout << min(ans + 2, n);
}
