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