#include <bits/stdc++.h>
int ans, p, q, n, m, i, j, k, a[100010];
char ch;
int main() {
  scanf("%d\n", &n);
  ans = 1;
  for (i = 1; i <= n; i++) {
    scanf("%c", &ch);
    if (ch == '1')
      a[i] = 1;
    else
      a[i] = 0;
  }
  for (i = 1; i < n; i++)
    if (a[i] != a[i + 1]) ans++;
  if (ans + 2 > n)
    ans = n;
  else
    ans += 2;
  printf("%d\n", ans);
  return 0;
}
