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