#include <bits/stdc++.h>
using namespace std;
int n, a[100010], l[100010], r[100010], ans, f1[100010][2], f2[100010][2];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    char x;
    cin >> x;
    if (x == '0')
      a[i] = 0;
    else
      a[i] = 1;
  }
  l[1] = 1;
  f1[1][a[1]] = 1;
  for (int i = 2; i <= n; ++i) {
    if (a[i] != a[i - 1])
      l[i] = l[i - 1];
    else
      l[i] = i;
    f1[i][0] = f1[i - 1][0];
    f1[i][1] = f1[i - 1][1];
    f1[i][a[i]] = max(f1[i][!a[i]], f1[i][!a[i]] + 1);
  }
  r[n] = n;
  f2[n][a[n]] = 1;
  for (int i = n - 1; i >= 1; --i) {
    if (a[i] != a[i + 1])
      r[i] = r[i + 1];
    else
      r[i] = i;
    f2[i][0] = f2[i + 1][0];
    f2[i][1] = f2[i + 1][1];
    f2[i][a[i]] = max(f2[i][a[i]], f2[i][!a[i]] + 1);
  }
  for (int i = 1; i <= n; ++i) {
    int tmp = f1[i - 1][a[i]] + r[i] - i + 1 + f2[r[i] + 1][a[r[i]]];
    ans = max(ans, tmp);
    if (r[i] != i) {
      tmp = f1[i - 1][a[i]] + (r[i] - 1) - i + 1 + f2[r[i]][!a[r[i]]];
      ans = max(ans, tmp);
    }
  }
  cout << ans;
  return 0;
}
