#include <bits/stdc++.h>
using namespace std;
int n, o = 0;
char s[100000] = {};
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> s;
  for (int i = 0; i < (n - 1); ++i) {
    if (s[i] != s[i + 1]) ++o;
  }
  cout << min(n, o + 3);
}
