#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
char str[100005];
int a[100005];
int main() {
  int i, j, n, m, sum, max1, fl, cnt;
  while (~scanf("%d", &n)) {
    scanf("%s", str + 1);
    for (i = 1; i <= n; i++) {
      a[i] = str[i] - '0';
    }
    int tmp;
    sum = 0;
    cnt = 0;
    max1 = -1;
    for (i = 1; i <= n;) {
      fl = 0;
      for (j = 0; j + i <= n; j++) {
        if (a[i + j] == a[i])
          continue;
        else {
          fl = 1;
          break;
        }
      }
      if (j == 2) cnt++;
      max1 = max(max1, j);
      sum++;
      i = i + j;
    }
    if (max1 == 1)
      printf("%d\n", sum);
    else if (max1 == 2) {
      if (cnt >= 2) {
        printf("%d\n", sum + 2);
      } else
        printf("%d\n", sum + 1);
    } else if (max1 >= 3)
      printf("%d\n", sum + 2);
  }
}
