#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2e5 + 8, inf = 1e18 + 9, mod = 1e9 + 7;
char s[maxn];
long long n, m;
void solve() {
  long long i, j, ans = 1;
  cin >> n >> (s + 1);
  for (i = 2; i <= n; i++)
    if (s[i] != s[i - 1]) ans++;
  cout << min(ans + 2, n) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  long long t = 1;
  while (t--) solve();
  return 0;
}
