#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  cin.ignore();
  string s;
  cin >> s;
  int las = 1;
  for (int i = 1; i < n; i++) {
    las += s[i] != s[i - 1];
  }
  int ans = min(n, las + 2);
  cout << ans << endl;
  return 0;
}
