#include <bits/stdc++.h>
using namespace std;
char a[222222];
int main() {
  int n, b = 0, s = 0;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    if (a[i] == a[i + 1])
      b++;
    else
      s++;
  }
  cout << s + min(2, b) << endl;
}
