#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
const long long MOD = 1e9 + 7;
const double eps = 1e-9;
int n;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  cin >> s;
  int ans = 0;
  for (int i = 1; i < n; i++) ans += (s[i] != s[i - 1]);
  cout << min(n, ans + 3) << "\n";
}
