#include <bits/stdc++.h>
auto thinking(const std::string& s) -> int64_t {
  if (s.size() == 0) return 0;
  int64_t count = 1;
  int last = s[0];
  for (auto it = std::begin(s) + 1; it != std::end(s); it++) {
    if (*it != last) {
      count++;
      last = *it;
    }
  }
  return std::min((int64_t)s.size(), count + 2);
}
auto main(int argc, char* argv[]) -> int {
  size_t size;
  std::cin >> size;
  std::string s;
  std::cin >> s;
  std::cout << thinking(s) << std::endl;
  return 0;
}
