#include <bits/stdc++.h>
int main() {
  int n, result, count = 0, i;
  scanf("%d", &n);
  char arr[n];
  for (i = 0; i < n; i++) {
    scanf("\n%c", &arr[i]);
  }
  i = 0;
  for (i = 0; i < n; i++) {
    if (arr[i] != arr[i - 1]) {
      count++;
    }
  }
  if (count + 2 < n) {
    result = count + 2;
  }
  if (count + 2 >= n) {
    result = n;
  }
  printf("%d", result);
}
