#include <bits/stdc++.h>
using namespace std;
int main() {
  string str;
  int n;
  cin >> n >> str;
  int a[n];
  for (int i = 0; i < n; ++i) {
    a[i] = str[i] - '0';
  }
  int f[2][2][3];
  memset(f, 0, sizeof(f));
  auto update = [](int &a, int b) -> void {
    if (a < b) a = b;
  };
  int u = 0, v = 1;
  for (int i = 0; i < n; ++i) {
    swap(u, v);
    memcpy(f[u], f[v], sizeof(f[u]));
    update(f[u][a[i]][0], f[v][a[i] ^ 1][0] + 1);
    update(f[u][a[i] ^ 1][1], max(f[v][a[i]][1], f[v][a[i]][0]) + 1);
    update(f[u][a[i]][2], max(f[v][a[i] ^ 1][2], f[v][a[i] ^ 1][1]) + 1);
  }
  int ans = 0;
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 3; ++j) ans = max(ans, f[u][i][j]);
  cout << ans << endl;
  return 0;
}
