#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int a[N];
string s;
int n;
int main() {
  cin >> n >> s;
  for (int i = 1; i <= n; ++i) a[i] = s[i - 1] - '0';
  int ans = 1;
  int pre = a[1];
  for (int i = 2; i <= n; ++i) {
    if (a[i] != pre) {
      pre = a[i];
      ans++;
    }
  }
  printf("%d\n", min(n, ans + 2));
}
