#include <bits/stdc++.h>
using namespace std;
const int64_t mod = 1000000007;
int64_t A[2001];
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int64_t n, ans = 1;
  string str;
  cin >> n >> str;
  for (int64_t i = 1; i < n; i++) ans += (str[i] != str[i - 1]);
  cout << min(ans + 2, n) << "\n";
}
