#include <bits/stdc++.h>
using namespace std;
const long long OO = 1e8;
const double EPS = (1e-7);
int dcmp(double x, double y) { return fabs(x - y) <= EPS ? 0 : x < y ? -1 : 1; }
int n;
string s;
int dp[100009][2][3];
int solveDP(int i, int prev, int op) {
  if (i == n) return op == 3;
  int& ret = dp[i][prev][op];
  if (ret != -1) return ret;
  ret = solveDP(i + 1, prev, op);
  if (op != 1 && (s[i] - '0') != prev)
    ret = max(ret, 1 + solveDP(i + 1, (s[i] - '0'), op));
  if (op == 1 && (s[i] - '0') == prev)
    ret = max(ret, 1 + solveDP(i + 1, prev ^ 1, op));
  if (op <= 1) ret = max(ret, solveDP(i, prev, op + 1));
  return ret;
}
int main() {
  cin >> n;
  cin >> s;
  memset(dp, -1, sizeof(dp));
  cout << max(solveDP(0, 0, 0), solveDP(0, 1, 0)) << endl;
}
