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