#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 0x3c3c3c3c;
const ll INFL = 0x3c3c3c3c3c3c3c3c;
const int MAX_N = 1e5 + 9;
int n;
string s;
int dp[MAX_N][3][2];
int getAnswer(int curr, int type, int need) {
  if (curr == n) {
    return 0;
  }
  if (type >= 3) {
    return 0;
  }
  int &res = dp[curr][type][need];
  if (res != -1) {
    return res;
  }
  int v = s[curr] - '0';
  if (v == need) {
    res = max(res, 1 + getAnswer(curr + 1, type, 1 - need));
  } else {
    res = max(res, getAnswer(curr + 1, type, need));
    res = max(res, getAnswer(curr, type + 1, 1 - need));
  }
  return res;
}
int main() {
  memset(dp, -1, sizeof(dp));
  cin >> n >> s;
  printf("%d", max(getAnswer(0, 0, 0), getAnswer(0, 0, 1)));
}
