#include <bits/stdc++.h>
using namespace std;
const long long linf = 1000000000000000043;
const int inf = 1000000043;
void pause(bool a = true) {}
template <class T>
inline T prod(pair<T, T> a, pair<T, T> b, pair<T, T> c = make_pair(0, 0)) {
  return (a.first - c.first) * (b.second - c.second) -
         (a.second - c.second) * (b.first - c.first);
}
template <class T>
inline bool intriangle(pair<T, T> a, pair<T, T> b, pair<T, T> c, pair<T, T> d) {
  return (abs(prod(a, b, c)) ==
          abs(prod(a, b, d)) + abs(prod(a, c, d)) + abs(prod(b, c, d)));
}
template <class T>
inline int sg(T a) {
  return (a < 0 ? -1 : a ? 1 : 0);
}
long long rng(long long a, long long b) {
  return (((((long long)rand()) << 16) + rand()) % (b - a + 1)) + a;
}
bool inConvPoly(vector<pair<long long, long long>> &a,
                pair<long long, long long> b) {
  long long l = 1;
  long long r = a.size() - 1;
  if (sg(prod(a[l], b, a[0])) * sg(prod(a[r], b, a[0])) >= 0) return false;
  if (intriangle(a[l], a[r], a[0], b)) return true;
  while (l != r - 1)
    (prod(a[(l + r) / 2], b, a[0]) < 0) ? l = (l + r) / 2 : r = (l + r) / 2;
  return sg(prod(b, a[r], a[l])) * sg(prod(b, a[0], a[l])) < 0;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
template <class T>
const T sqr(const T x) {
  return abs(x * x);
}
unsigned long long powi(unsigned long long a, unsigned long long b,
                        long long mod = 1000000007) {
  if (b < 2) return b ? a : 1;
  return (powi((a * a) % mod, b / 2, mod) * (b % 2 ? a : 1)) % mod;
}
bool isn(char c) { return ('0' <= c && c <= '9'); }
template <class T>
bool read(T &out) {
  int c = getchar(), sign = 1;
  T num = 0;
  for (; !isn(c) && c != '-'; c = getchar())
    if (c == EOF) return false;
  if (c == '-') {
    sign = -1;
    c = getchar();
  }
  if (c == EOF) return false;
  for (; isn(c); c = getchar()) num = num * 10 + c - '0';
  out = sign * num;
  return true;
}
long long time_limit = 1000000;
long long start = clock();
bool time_break() {
  int g = clock();
  return (clock() - start > time_limit * 0.8);
}
long long fact(long long n, long long mod = linf) {
  long long g = 1;
  for (int i = 0; i < (n - 1); i++) g *= (i + 1);
  return g;
}
void init(long long tl = 1000000) {
  ios::sync_with_stdio(false);
  srand(time(0));
  time_limit = tl;
}
template <class T>
void maxz(T &a, T b) {
  a = max(a, b);
}
template <class T>
void minz(T &a, T b) {
  a = min(a, b);
}
long long mod = 1000000007;
bool isprime(long long n) {
  if (n < 2) return 0;
  for (long long i = 2; i * i <= n; i++)
    if (n % i == 0) return 0;
  return 1;
}
long long randLL() {
  return (((long long)rand()) << 47) + (((long long)rand()) << 31) +
         (((long long)rand()) << 15) + (((long long)rand()) >> 1);
}
bool isprimeL(long long n, int it = 50) {
  if (n < 2) return 0;
  if (n == 2) return 1;
  if (n % 2 == 0) return 0;
  for (int i = 0; i < (it); i++) {
    long long x = randLL() % (n - 1) + 1;
    if (gcd(x, n) != 1) return 0;
    if (powi(x, n - 1, n) != 1) return 0;
  }
  return 1;
}
bool check(const vector<long long> &a, long long s, long long k) {
  vector<long long> b(k, s);
  multiset<long long> st;
  for (int i = 0; i < (a.size()); i++) st.insert(-a[i]);
  for (int i = 0; i < (k); i++) {
    if (st.empty()) break;
    b[i] += *st.begin();
    st.erase(st.begin());
    if (st.empty()) break;
    if (st.lower_bound(-b[i]) != st.end()) {
      int g = b[i];
      if (b[i] >= -(*st.lower_bound(-b[i]))) {
        b[i] += *st.lower_bound(-b[i]);
        st.erase(st.lower_bound(-g));
      }
    }
  }
  return st.empty();
}
int main() {
  init();
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (int i = 0; i < (n); i++) {
    char c;
    cin >> c;
    a[i] = c - '0';
  }
  long long ans = 1;
  for (int i = 0; i < (n - 1); i++) {
    if (a[i] != a[i + 1]) ans++;
  }
  long long cnt = 0;
  for (int i = 0; i < (n - 1); i++) cnt += (a[i] == a[i + 1]);
  if (cnt >= 2) ans += 2;
  if (cnt == 1) ans += 1;
  cout << ans << endl;
  pause();
  return 0;
}
