#include <bits/stdc++.h>
using namespace std;
long long n, prv[100005][2];
bool a[100005];
long long dp[100005][3];
long long solve(long long i, long long flip) {
  if (i == -1) return 0;
  if (dp[i][flip] == -1) {
    long long ans = 0;
    long long prev_op = prv[i][!a[i]], prev_same = prv[i][a[i]];
    if (flip == 2) {
      ans = max(ans, 1 + solve(prev_op, 2));
      ans = max(ans, 1 + solve(prev_same, 1));
    } else if (flip == 1) {
      ans = max(ans, 1 + solve(prev_op, 1));
      ans = max(ans, 1 + solve(prev_same, 0));
    } else
      ans = max(ans, 1 + solve(prev_op, 0));
    dp[i][flip] = ans;
  }
  return dp[i][flip];
}
int main() {
  memset(dp, -1, sizeof(dp));
  scanf("%lld", &n);
  string temp;
  cin >> temp;
  for (int i = 0; i < n; i++) a[i] = temp[i] - '0';
  prv[0][0] = prv[0][1] = -1;
  for (int i = 0; i < n - 1; i++) {
    prv[i + 1][0] = prv[i][0];
    prv[i + 1][1] = prv[i][1];
    prv[i + 1][a[i]] = i;
  }
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long ans_i = solve(i, 2);
    ans = max(ans, ans_i);
  }
  printf("%lld", ans);
  return 0;
}
