#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  long long n, i, maxx = -1e17, ans = 1;
  string s;
  cin >> n;
  cin >> s;
  for (i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) ++ans;
  }
  cout << min(ans + 2, n);
  return 0;
}
