#include <bits/stdc++.h>
void solve() {
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;
  int r = 0;
  for (int i = 1; i < n; ++i) {
    r += (s[i] != s[i - 1]);
  }
  r = std::min(r + 3, n);
  std::cout << r;
}
int main() {
  solve();
  return 0;
}
