#include <bits/stdc++.h>
int main() {
  std::ios_base::sync_with_stdio(false);
  int N, sol = 1;
  std::string S;
  std::cin >> N >> S;
  for (int i = 0; i < N - 1; i++) sol += (S[i] != S[i + 1]);
  std::cout << std::min(N, sol + 2);
  return 0;
}
