#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1);
int n;
string s;
int main() {
  cin >> n;
  cin >> s;
  int ans = 1;
  for (int i = 1; i < n; ++i) ans += s[i] != s[i - 1];
  ans = min(n, ans + 2);
  cout << ans << endl;
  return 0;
}
