#include <bits/stdc++.h>
using namespace std;
const int MAX = 100010;
const long long mod = 1000000007;
int main() {
  long long c0, c1, i, n, ans;
  string s;
  cin >> n >> s;
  ans = 1;
  for (int i = 1; i < (n); i++)
    if (s[i] != s[i - 1]) ans++;
  c0 = 0;
  c1 = 0;
  for (int i = 1; i < (n); i++)
    if (s[i] == s[i - 1]) c0++;
  if (c0 == 1)
    ans++;
  else if (c0)
    ans += 2;
  cout << ans << endl;
  return 0;
}
