#include <bits/stdc++.h>
using namespace std;
string s;
vector<int> v;
int n, h, dp[100005][3][3][3];
int solve(int idx, int pv, bool f, bool can) {
  if (idx >= n) return 0;
  int &x = dp[idx][pv][f][can];
  if (~x) return x;
  x = max(solve(idx + 1, pv, f, can), x);
  if (!f) {
    if (v[idx] != pv) x = max(solve(idx + 1, !pv, f, can) + 1, x);
    if (v[idx] == pv) x = max(x, solve(idx + 1, !pv, !f, can) + 1);
  } else {
    if (!can && v[idx] == pv) x = max(x, solve(idx + 1, !pv, f, can) + 1);
    if (!can && v[idx] != pv) x = max(x, solve(idx + 1, !pv, f, !can) + 1);
    if (can && v[idx] != pv) x = max(x, solve(idx + 1, !pv, f, can) + 1);
  }
  return x;
}
int main() {
  ios::sync_with_stdio(0);
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n >> s;
  for (auto u : s) v.push_back(u - '0');
  memset(dp, -1, sizeof(dp));
  (v[0] == 0) ? h = 1 : h = 0;
  int ans = solve(0, h, 0, 0);
  memset(dp, -1, sizeof(dp));
  int ans2 = solve(0, !h, 0, 0);
  cout << max(ans, ans2) << "\n";
  return 0;
}
