#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using llu = unsigned long long;
using ld = long double;
const double PI = acos(-1.0), g = 9.80665;
const ll inf = 1e18 + 505;
ll i, j, k, n, m, cnt;
bool is;
void solve(void) {
  cin >> n;
  string s;
  cin >> s;
  ll len = 1;
  for (i = 1; i < n; i++)
    if (s[i] != s[i - 1]) len++;
  cout << min(len + 2ll, n);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int testcase = 1;
  while (testcase--) {
    solve();
  }
  return 0;
}
