#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long maxn = 1e5 + 10, inf = 4e18, mod = 1e9 + 7;
const long double pi = 3.14159265359, eps = 1e-9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, tn = 0;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 1; i < n; i++) {
    tn += (s[i] != s[i - 1]);
  }
  cout << min(tn + 2 + 1, n);
  return 0;
}
