#include <bits/stdc++.h>
int main() {
  std::ios::sync_with_stdio(false);
  int n, res = 3;
  std::cin >> n;
  char ch[100005];
  std::cin >> ch;
  for (size_t i = 1; i != n; ++i) {
    res += (ch[i] != ch[i - 1]);
  }
  res = res > n ? n : res;
  std::cout << res << std::endl;
  return 0;
}
