#include <bits/stdc++.h>
using namespace std;
const int maxn = 100010;
char s[maxn];
int main(void) {
  int n, x, y;
  cin >> n >> s;
  x = 0, y = 1;
  for (int i = 1; i < strlen(s); i++) {
    if (s[i] != s[i - 1])
      y++;
    else
      x++;
  }
  cout << y + min(x, 2) << endl;
  return 0;
}
