#include <bits/stdc++.h>
using namespace std;
const long long int MAX = 1e7 + 7;
const long long int MOD = 1000000007;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
void read(long long int n, vector<long long int> &v) {
  for (long long int i = 0; i < n; i++) cin >> v[i];
}
vector<long long int> dp;
long long int n;
string s;
int main() {
  fast();
  long long int TEST_CASES = 1;
  while (TEST_CASES--) {
    cin >> n;
    cin >> s;
    if (n <= 3)
      cout << n << "\n";
    else {
      long long int tot = 1;
      for (int i = 1; i < n; i++) tot += (s[i] != s[i - 1]);
      tot = min(n, tot + 2);
      cout << tot << "\n";
    }
  }
  return 0;
}
