#include <bits/stdc++.h>
using namespace std;
int solve(string s) {
  int n = s.size();
  int sol = 0;
  int i = 0, nr_secv = 0;
  while (i < n) {
    nr_secv++;
    int j = i, lungime = 0;
    while (j < n && s[i] == s[j]) {
      j++;
      lungime++;
    }
    i = j;
  }
  return (n) < (nr_secv + 2) ? (n) : (nr_secv + 2);
}
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  cout << solve(s);
  return 0;
}
