#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  string s;
  cin >> s;
  long long len = 1;
  for (long long i = 1; i < n; i++)
    if (s[i] != s[i - 1]) len++;
  cout << min(len + 2, n);
}
