#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const int INF = 0x7f7f7f7f;
int main() {
  ios_base::sync_with_stdio(false);
  int n, cnt = 1;
  string str;
  cin >> n >> str;
  for (int i = 1; i <= n - 1; i++) {
    if (str[i] != str[i - 1]) cnt++;
  }
  int ans = min(cnt + 2, n);
  cout << ans;
  return 0;
}
