#include <bits/stdc++.h>
using namespace std;
long long int n;
void solve() {
  cin >> n;
  string s;
  cin >> s;
  int ccnt = 1;
  vector<long long int> seg;
  for (int i = 1; i < n; i++) {
    if (s[i] == s[i - 1])
      ccnt++;
    else {
      seg.push_back(ccnt);
      ccnt = 1;
    }
  }
  seg.push_back(ccnt);
  sort(seg.begin(), seg.end());
  if (seg.size() == 1) {
    if (seg[0] >= 3) {
      cout << 3 << endl;
    } else if (seg[0] == 2)
      cout << 2 << endl;
    else
      cout << 1 << endl;
    return;
  }
  if (seg[seg.size() - 1] >= 3) {
    cout << seg.size() + 2 << endl;
  } else if (seg[seg.size() - 2] >= 2) {
    cout << seg.size() + 2 << endl;
    return;
  } else if (seg[seg.size() - 1] >= 2) {
    cout << seg.size() + 1 << endl;
  } else {
    cout << seg.size() << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  while (t--) solve();
}
