#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n;
  string s;
  cin >> s;
  int l = s.length(), ct = 1;
  for (int i = 1; i < l; i++) {
    if (s[i] != s[i - 1]) ct++;
  }
  if (ct >= (n - 1))
    cout << n;
  else
    cout << ct + 2;
  return 0;
}
