#include <bits/stdc++.h>
namespace ZZ {
const long double PI = acos(-1);
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
void invec(vector<long long> &a) {
  for (long long i = 0; i < a.size(); i++) {
    cin >> a[i];
  }
}
long long pow(long long a, long long b, long long m) {
  long long ans = 1;
  while (b) {
    if (b % 2) ans = (ans * a) % m, b--;
    a = (a * a) % m, b >>= 1;
  }
  return ans;
}
struct dsu {
  vector<long long> prnt, sz;
  dsu(long long n) {
    prnt = vector<long long>(n + 1);
    sz = vector<long long>(n + 1);
    for (long long i = 0; i <= n; i++) prnt[i] = i, sz[i] = 1;
  }
  long long find_prnt(long long u) {
    return (u == prnt[u] ? u : prnt[u] = find_prnt(prnt[u]));
  }
  void unite(long long u, long long v) {
    long long a = find_prnt(u), b = find_prnt(v);
    if (a == b) return;
    if (sz[a] >= sz[b])
      prnt[b] = a, sz[a] += sz[b];
    else
      prnt[a] = b, sz[b] += sz[a];
  }
};
void vvlog(vector<vector<long long> > &a) {
  for (long long i = 0; i < a.size(); i++) {
    for (long long j = 0; j < a[i].size(); j++) cout << a[i][j] << " ";
    cout << "\n";
    ;
  }
}
}  // namespace ZZ
using namespace ZZ;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, cnt = 1, fs = 0;
  cin >> n;
  string s;
  cin >> s;
  vector<vector<long long> > a(2);
  for (long long i = 0; i < n; i++) {
    if (s[i] == '1')
      a[1].emplace_back(i);
    else
      a[0].emplace_back(i);
  }
  long long find = s[0] - '0', sch = 0;
  while (1) {
    find = !find;
    if (find) {
      long long ind = lower_bound(a[1].begin(), a[1].end(), sch) - a[1].begin();
      if (ind == a[1].size()) break;
      cnt++;
      sch = a[1][ind];
    } else {
      long long ind = lower_bound(a[0].begin(), a[0].end(), sch) - a[0].begin();
      if (ind == a[0].size()) break;
      cnt++;
      sch = a[0][ind];
    }
  }
  long long i = 0, j = 2;
  while (j < n) {
    long long f = 1;
    for (long long k = i; k <= j; k++)
      if (s[k] != s[i]) f = 0;
    if (f) {
      cnt += 2;
      goto jump;
    }
    i++;
    j++;
  }
  i = 0;
  j = 1;
  while (j < n) {
    if (s[i] == s[i + 1]) fs++;
    i++;
    j++;
  }
  if (fs == 1) {
    cnt++;
    goto jump;
  } else if (fs >= 2) {
    cnt += 2;
    goto jump;
  }
  if (n >= 2) {
    if (s[0] == s[1]) {
      cnt++;
      goto jump;
    }
  }
  if (n >= 2) {
    if (s[n - 1] == s[n - 2]) {
      cnt++;
      goto jump;
    }
  }
jump:;
  cout << cnt << "\n";
}
