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