#include <bits/stdc++.h>
using namespace std;
char s[100005];
int main() {
  int a = 0, b = 0, n;
  scanf("%d", &n);
  scanf("%s", s);
  for (int i = 0; i < n; i++) {
    if (s[i] == '1')
      a = max(a, b + 1);
    else
      b = max(b, a + 1);
  }
  printf("%d\n", min(n, max(a, b) + 2));
}
