#include <bits/stdc++.h>
int compute(char*, int);
int max_distance(char*, int);
int main() {
  int s = 0;
  int n = 0;
  int i = 0;
  int d = 0;
  char *seq, c;
  scanf("%d%c", &n, &c);
  seq = (char*)malloc(sizeof(char) * n);
  for (i = 0; i < n; i++) scanf("%c", &seq[i]);
  s = compute(seq, n);
  d = max_distance(seq, n);
  if (d > 2) s += 2;
  if (d == 2) s++;
  printf("%d", s);
  return 0;
}
int compute(char* seq, int n) {
  int result = 0;
  int i = 0;
  char tmp = '.';
  for (i = 0; i < n; i++) {
    if (tmp != seq[i]) {
      tmp = seq[i];
      result++;
    }
  }
  return result;
}
int max_distance(char* seq, int n) {
  int result = 0;
  int i = 0;
  char tmp = '.';
  int b = 0;
  int f = 0;
  for (i = 0; i < n; i++) {
    if (tmp != seq[i]) {
      if ((f - b) >= 2) {
        result += (f - b);
        if (result > 2) return result;
      }
      tmp = seq[i];
      b = i;
    } else {
      f = i + 1;
    }
    if ((i == n - 1) && tmp == seq[i]) {
      if ((n - b) >= 2) {
        result += (n - b);
        if (result > 2) return result;
      }
    }
  }
  return result;
}
