#include <bits/stdc++.h>
using namespace std;
const long double EPS = 1e-8;
const int INF = (int)(1e8);
const long long mod = (int)(1e+9 + 7);
const int N = (int)(1e5);
int days_month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  int cnt = 1;
  for (int i = (1); i <= (n - 1); i++) {
    if (s[i - 1] != s[i]) cnt++;
  }
  cout << min(cnt + 2, n);
  return 0;
}
