#include <bits/stdc++.h>
using namespace std;
const int MAX = 100001;
const int mod = 1e9 + 7;
vector<int> g[MAX];
int par[MAX];
bool vis[MAX];
long long powr(long long a, long long n, long long m) {
  long long res = 1;
  a = a % m;
  while (n) {
    if (n & 1) {
      res = (res * a) % m;
    }
    a = (a * a) % m;
    n >>= 1;
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1]) ans++;
  }
  ans = min(ans + 2, n);
  cout << ans;
}
