#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000050;
char s[maxn];
int cnt[maxn], val[maxn];
int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    scanf("%s", s);
    int add = 0;
    int m = 0;
    cnt[0] = 1;
    val[0] = s[0] - '0';
    for (int i = 1; i < n; i++) {
      if (s[i] != s[i - 1]) {
        m++;
        val[m] = s[i] - '0';
        cnt[m] = 0;
      }
      cnt[m]++;
    }
    printf("%d\n", min(m + 1 + 2, n));
  }
  return 0;
}
