#include <bits/stdc++.h>
using namespace std;
const int maxn = 0x7f7f7f7f;
const int maxx = 1e6 + 10;
int a[maxx];
int main() {
  int n;
  string s;
  cin >> n;
  cin >> s;
  int cnt = 1;
  char c = s[0];
  for (int i = 1; i < n; i++) {
    if (c != s[i]) {
      c = s[i];
      cnt++;
    }
  }
  if (cnt >= n - 2)
    cout << n << endl;
  else
    cout << cnt + 2 << endl;
  return 0;
}
