#include <bits/stdc++.h>
using namespace std;
int a[111111];
char ch[111111];
int main() {
  int n, k;
  while (~scanf("%d", &n)) {
    scanf("%s", ch + 1);
    for (int i = 1; i <= n; i++) a[i] = ch[i] - '0';
    int ans = 1;
    int now = a[1];
    for (int i = 2; i <= n; i++) {
      if (a[i] != now) ans++;
      now = a[i];
    }
    now = a[1];
    int tlen = 1;
    int id1 = 1;
    for (int i = 2; i <= n; i++) {
      if (now == a[i])
        tlen++;
      else {
        if (tlen > 1) {
          id1 = i - 1;
          break;
        }
        tlen = 1;
        now = a[i];
      }
    }
    if (id1 == 1 && tlen > 1) id1 = n;
    tlen = 1;
    now = a[n];
    int id2 = n;
    for (int i = n - 1; i >= 1; i--) {
      if (now == a[i])
        tlen++;
      else {
        if (tlen > 1) {
          id2 = i + 1;
          break;
        }
        tlen = 1;
        now = a[i];
      }
    }
    if (id2 == n && tlen > 1) id2 = 1;
    if (id2 + tlen - 1 == id1 && a[id1] == a[id2] && tlen > 1) {
      if (tlen >= 3)
        ans += 2;
      else
        ans++;
    } else if (tlen > 1)
      ans += 2;
    else
      ans += 0;
    printf("%d\n", ans);
  }
  return 0;
}
