#include <bits/stdc++.h>

using namespace std;
const int N = 100100;
char s[N];

int main() {
    int n, cnt = 0;
    scanf("%d%s", &n, s);
    for (int i = 0, p = 0; i < n; i++)
        if (p != s[i])
            p = s[i], cnt++;
    printf("%d", min(n, cnt + 2));
    return 0;
}