#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 7;
const int oo = 1e9 + 7;
int n;
int a[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cin >> n;
  int res = 1;
  for (int i = 1; i <= n; i++) {
    char ch;
    cin >> ch;
    a[i] = ch - '0';
    if (a[i] != a[i - 1] && i != 1) res++;
  }
  res = min(res + 2, n);
  cout << res << "\n";
  return 0;
}
