#include <bits/stdc++.h>
using namespace std;
char s[100005];
int f[100005][2][3];
int main() {
  int n;
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; ++i) {
    int t = s[i] - 48;
    f[i][t][0] = f[i - 1][t ^ 1][0] + 1;
    f[i][t ^ 1][0] = f[i - 1][t ^ 1][0];
    f[i][t][1] = max(f[i - 1][t ^ 1][1], f[i - 1][t ^ 1][2]) + 1;
    f[i][t ^ 1][1] = max(f[i - 1][t ^ 1][1], f[i - 1][t ^ 1][2]);
    f[i][t ^ 1][2] = max(f[i - 1][t][2], f[i - 1][t][0]) + 1;
    f[i][t][2] = max(f[i - 1][t][2], f[i - 1][t][0]);
  }
  int ans = 0;
  for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 3; ++j) ans = max(ans, f[n][i][j]);
  cout << ans << endl;
  return 0;
}
