#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  char x;
  cin >> n;
  char prev = 'x';
  int scorea = 0, scoreb = 0;
  int c = 1;
  cin >> prev;
  char f;
  for (int i = 1; i < n; i++) {
    cin >> x;
    if (abs(x - prev) == 1) {
      c++;
    }
    if (x - prev == 0 && prev == '0' && scorea < 2) {
      scorea++;
    }
    if (x - prev == 0 && prev == '1' && scoreb < 2) {
      scoreb++;
    }
    prev = x;
  }
  if (scorea + scoreb <= 2) {
    cout << c + scorea + scoreb;
  } else
    cout << c + max(scorea, scoreb);
  return 0;
}
