#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, x, y;
  string s;
  cin >> n >> s;
  x = 1;
  for (i = 1; i < n; i++) {
    if (s[0] != s[i]) x++;
    s[0] = s[i];
  }
  y = min(2, n - x);
  cout << x + y;
}
