#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
const int Sz = 1e5 + 3;
const ll MOD = 1e9 + 7;
const int oo = 1e9;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  string s;
  int n;
  cin >> n;
  cin >> s;
  int ans = 3;
  for (int i = (1); i <= (n - 1); ++i) {
    ans += (s[i] != s[i - 1]);
  }
  cout << min(ans, n);
  return 0;
}
