#include <bits/stdc++.h>
using namespace std;
int dp[100010][2][3];
int n;
string A;
int f(int i, int b, int state) {
  if (state == 3) return 0;
  if (i == n) return 0;
  if (dp[i][b][state] != -1) return dp[i][b][state];
  int ans = 0;
  int cbit = A[i] - '0';
  if (state == 1) {
    cbit = (cbit + 1) % 2;
  }
  if (cbit == b) {
    ans = max(ans, 1 + f(i + 1, (b + 1) % 2, state));
    ans = max(ans, 1 + f(i + 1, (b + 1) % 2, state + 1));
  } else {
    ans = max(ans, f(i + 1, b, state));
    ans = max(ans, f(i + 1, b, state + 1));
  }
  return dp[i][b][state] = ans;
}
int main(int argc, char const *argv[]) {
  memset(dp, -1, sizeof(dp));
  cin >> n;
  cin >> A;
  int ans = 0;
  ans = max(ans, f(0, 0, 0));
  ans = max(ans, f(0, 1, 0));
  ans = max(ans, f(0, 0, 1));
  ans = max(ans, f(0, 1, 1));
  cout << ans << endl;
  return 0;
}
