#include <bits/stdc++.h>
using namespace std;
inline int solve(string a) {
  if (a.length() < 4) return a.length();
  int f2 = 0, f3 = 0;
  for (int i = 2; i < a.length(); i += 1) {
    if (a[i] == a[i - 1] and a[i - 1] == a[i - 2]) {
      f3 = 1;
    } else if (a[i] == a[i - 1]) {
      f2 += 1;
    } else {
    }
  }
  if (a[0] == a[1]) f2 += 1;
  int altseq = 1;
  for (int i = 1; i < a.length(); i += 1) {
    if (a[i] != a[i - 1]) altseq += 1;
  }
  if (f3 or f2 > 1) return altseq + 2;
  if (f2) return altseq + 1;
  return altseq;
}
int main(void) {
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  string a;
  cin >> a;
  cout << solve(a) << endl;
}
