#include <bits/stdc++.h>
using namespace std;
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1};
int dy8[] = {1, -1, -1, 0, 1, -1, 0, 1};
int dp[100005][3][3];
int nxtz[100005], nxto[100005], n;
string s;
int dpcall(int id, int lst, int ok) {
  if (id == n) return 0;
  int &ret = dp[id][lst][ok];
  if (~ret) return ret;
  ret = 0;
  if (ok == 2) {
    if (s[id] == lst + '0') {
      ret = dpcall(id + 1, lst, ok);
    } else {
      ret = 1 + dpcall(id + 1, s[id] - '0', ok);
    }
  } else if (ok == 0) {
    if (lst == s[id] - '0') {
      ret = dpcall(id + 1, lst, ok);
      ret = max(ret, dpcall(id + 1, lst ^ 1, 1));
    } else {
      ret = 1 + dpcall(id + 1, s[id] - '0', ok);
      ret = max(ret, 1 + dpcall(id + 1, (s[id] - '0' ^ 1), 1));
    }
  } else if (ok == 1) {
    if (lst == s[id] - '0') {
      ret = dpcall(id + 1, lst, ok);
      ret = max(ret, dpcall(id + 1, lst ^ 1, 2));
    } else {
      ret = 1 + dpcall(id + 1, s[id] - '0', ok);
      ret = max(ret, 1 + dpcall(id + 1, (s[id] - '0' ^ 1), 2));
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  memset((dp), -1, sizeof(dp));
  cin >> n;
  cin >> s;
  int z = n, o = n;
  for (int i = n - 1; i >= 0; i--) {
    nxtz[i] = z;
    nxto[i] = o;
    if (s[i] == '1')
      o = i;
    else
      z = i;
  }
  int ans = 0, res = 0;
  for (int i = 0; i < n; i++) {
    ans = max(dpcall(i, 2, 0), dpcall(i, 2, 1));
    res = max(res, ans);
  }
  cout << res << endl;
  return 0;
}
