#include <bits/stdc++.h>
using namespace std;
const unsigned long long M = 998244353;
void solve() {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long res = 1;
  long long ct = 1;
  for (long long i = 1; i < n; i++) {
    if (s[i - 1] == s[i])
      ct++;
    else {
      res++;
      ct = 1;
    }
  }
  cout << min(res + 2, n);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  while (t--) {
    solve();
  }
}
