#include <bits/stdc++.h>
using namespace std;
int main() {
  int ar[100000], ar1[100000];
  char s;
  long long n, i, m;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> s;
    if (s == '0')
      ar[i] = 0;
    else
      ar[i] = 1;
  }
  ar1[0] = 1;
  for (i = 1; i < n; i++) {
    ar1[i] = (ar1[i - 1] + abs(ar[i] - ar[i - 1]));
  }
  if (ar1[n - 1] + 2 >= n)
    cout << n;
  else
    cout << ar1[n - 1] + 2;
  return 0;
}
