#include <bits/stdc++.h>
using namespace std;
int n;
char digits[100002];
int lasBeforeChangeWithZero[100002];
int lasBeforeChangeWithOne[100002];
int lasDuringChangeWithZero[100002];
int lasDuringChangeWithOne[100002];
int lasAfterChangeWithZero[100002];
int lasAfterChangeWithOne[100002];
int main() {
  scanf("%d", &n);
  getchar();
  fgets(digits, n + 1, stdin);
  if (digits[0] == '0') {
    lasBeforeChangeWithZero[0] = 1;
    lasDuringChangeWithOne[0] = 1;
  } else {
    lasBeforeChangeWithOne[0] = 1;
    lasDuringChangeWithZero[0] = 1;
  }
  for (int i = 1; i < n; ++i) {
    lasBeforeChangeWithZero[i] = lasBeforeChangeWithZero[i - 1];
    lasBeforeChangeWithOne[i] = lasBeforeChangeWithOne[i - 1];
    lasDuringChangeWithZero[i] = lasDuringChangeWithZero[i - 1];
    lasDuringChangeWithOne[i] = lasDuringChangeWithOne[i - 1];
    lasAfterChangeWithZero[i] = lasAfterChangeWithZero[i - 1];
    lasAfterChangeWithOne[i] = lasAfterChangeWithOne[i - 1];
    if (digits[i] == '0') {
      lasBeforeChangeWithZero[i] = lasBeforeChangeWithOne[i - 1] + 1;
      lasDuringChangeWithOne[i] = max(lasDuringChangeWithZero[i - 1] + 1,
                                      lasBeforeChangeWithZero[i - 1] + 1);
      lasAfterChangeWithZero[i] = max(lasAfterChangeWithOne[i - 1] + 1,
                                      lasDuringChangeWithOne[i - 1] + 1);
    } else {
      lasBeforeChangeWithOne[i] = lasBeforeChangeWithZero[i - 1] + 1;
      lasDuringChangeWithZero[i] = max(lasDuringChangeWithOne[i - 1] + 1,
                                       lasBeforeChangeWithOne[i - 1] + 1);
      lasAfterChangeWithOne[i] = max(lasAfterChangeWithZero[i - 1] + 1,
                                     lasDuringChangeWithZero[i - 1] + 1);
    }
  }
  printf("%d", max(max(max(lasDuringChangeWithZero[n - 1],
                           lasDuringChangeWithOne[n - 1]),
                       lasAfterChangeWithZero[n - 1]),
                   lasAfterChangeWithOne[n - 1]));
  return 0;
}
