#include <bits/stdc++.h>
using namespace std;
void cline() { cout << '\n'; }
template <typename T, typename... V>
void cline(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ' ';
  cline(v...);
}
void cspc() { cout << ' '; }
template <typename T, typename... V>
void cspc(T t, V... v) {
  cout << t;
  if (sizeof...(v)) cout << ' ';
  cspc(v...);
}
const int N = 1e6 + 4;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int inl = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1]) inl++;
  }
  int flag = 0;
  for (int i = 0; i <= n - 2; ++i) {
    if ((s[i] == s[i + 1])) {
      flag++;
    }
  }
  if (flag > 1) inl += 2;
  if (flag < 2) {
    for (int i = 0; i < n - 1; ++i) {
      if (i != n - 2) {
        if ((s[i] == s[i + 1])) {
          if (s[i + 1] == s[i + 2]) inl++;
          inl++;
          break;
        }
      } else {
        if (s[i] == s[i + 1]) {
          inl++;
          break;
        }
      }
    }
  }
  cline(inl);
  return 0;
}
