#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, cnt = 1, one = 0, zero = 0;
  cin >> n;
  char a[n], m;
  cin >> m;
  if (m == '1')
    one = 1;
  else
    zero = 1;
  for (int i = 1; i < n; i++) {
    cin >> a[i];
    if (a[i] == '1' && zero == 1) {
      cnt++;
      zero = 0;
      one = 1;
    } else if (a[i] == '0' && one == 1) {
      cnt++;
      one = 0;
      zero = 1;
    }
  }
  if (cnt == n || cnt == n - 1)
    cout << n;
  else {
    cout << cnt + 2;
  }
}
