#include <bits/stdc++.h>
using namespace std;
int n;
char T[100000 + 1];
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> T;
  for (int a = 0; a < n; ++a) T[a] -= '0';
  int ret1 = 0, ret2 = 0, i1 = 0, i2 = 1;
  for (int a = 0; a < n; ++a) {
    if (T[a] == i1) {
      ++ret1;
      i1 = !i1;
    }
    if (T[a] == i2) {
      ++ret2;
      i2 = !i2;
    }
  }
  cout << min(max(ret1, ret2) + 2, n);
  return 0;
}
