#include <bits/stdc++.h>
const int mod = (int)1e9 + 7;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  string s;
  cin >> n >> s;
  char c = s[0];
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != c) {
      c = s[i];
      ans++;
    }
  }
  cout << min(n, ans + 2) << "\n";
  return 0;
}
