#include <bits/stdc++.h>
using namespace std;
const int N = 1E5 + 5;
int n, f1, f2, f[N], g[N], p[N], last, ans;
char s[N];
int main() {
  scanf("%d\n%s", &n, s + 1);
  for (int i = 1; i <= n; i++)
    if (s[i] == '0') {
      f1 = f[i] = f2 + 1;
    } else
      f2 = f[i] = f1 + 1;
  f1 = f2 = 0;
  for (int i = n; i; i--)
    if (s[i] == '0') {
      f1 = g[i] = f2 + 1;
    } else
      f2 = g[i] = f1 + 1;
  for (int i = n; i; i--) {
    p[i] = last ? last : i + 1;
    if (s[i] == s[i + 1]) last = i + 1;
  }
  for (int i = 1; i <= n; i++) ans = max(ans, f[i] + g[p[i]] + p[i] - i - 1);
  cout << ans;
}
