#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  string s;
  cin >> s;
  vector<long long int> ind;
  long long int t = 0;
  ind.push_back(0);
  for (long long int i = 1; i < n; i++) {
    if (s[i] != s[ind[t]]) {
      t++;
      ind.push_back(i);
    }
  }
  long long int f = 0;
  long long int last = 0;
  for (long long int i = 1; i <= t; i++) {
    if (ind[i] - ind[i - 1] - 1 >= 2) {
      f = 1;
      break;
    }
    if (ind[i] - ind[i - 1] - 1 >= 1) {
      last++;
    }
  }
  if (n - ind[t] - 1 >= 2) f = 1;
  if (n - ind[t] - 1 >= 1) last++;
  if (last >= 2) f = 1;
  if (f == 1) {
    cout << ind.size() + 2 << "\n";
  } else if (last >= 1) {
    cout << ind.size() + 1 << "\n";
  } else {
    cout << ind.size() << "\n";
  }
}
