#include <bits/stdc++.h>
using namespace std;
const int N = 142123;
const int md = 1e9 + 7;
char ch;
int n, s[N][2], a[N], d[N][2], ans;
int f[N][2];
void g(int first) { ans = max(ans, first); }
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> ch, a[i] = ch - '0';
  for (int i = 1; i <= n; ++i) {
    d[i][1] = d[i - 1][1];
    d[i][0] = d[i - 1][0];
    d[i][a[i]] = max(d[i][a[i]], d[i - 1][1 - a[i]] + 1);
  }
  for (int i = n; i >= 1; --i) {
    s[i][1] = s[i + 1][1];
    s[i][0] = s[i + 1][0];
    s[i][a[i]] = max(s[i][a[i]], s[i + 1][1 - a[i]] + 1);
    f[i][1] = f[i + 1][1];
    f[i][0] = f[i + 1][0];
    f[i][1 - a[i]] = max(f[i][1 - a[i]], s[i + 1][a[i]] + 1);
    f[i][1 - a[i]] = max(f[i][1 - a[i]], f[i + 1][a[i]] + 1);
  }
  g(d[n][1]);
  g(d[n][0]);
  g(s[1][0]);
  g(s[1][1]);
  g(f[1][0]);
  g(f[1][1]);
  for (int i = 1; i <= n; ++i) {
    g(d[i][0] + f[i + 1][1]);
    g(d[i][1] + f[i + 1][0]);
  }
  cout << ans;
}
