#include <bits/stdc++.h>
using namespace std;
int prefix[200007], suffix[200007], maxi = 0;
void precal(string s) {
  int cnt = 0;
  bool zero;
  if (s[0] == '0')
    zero = 1;
  else
    zero = 0;
  for (int i = 0; i < s.size(); ++i) {
    if (zero && s[i] == '0') {
      ++cnt;
      zero = 0;
    } else if (!zero && s[i] == '1') {
      ++cnt;
      zero = 1;
    }
    prefix[i] = cnt;
  }
  maxi = max(maxi, cnt);
  cnt = 0;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, j;
  string s;
  cin >> n >> s;
  precal(s);
  int fst = -1, lst = -1;
  for (int i = 0; i < s.size() - 1; ++i) {
    if (s[i] == s[i + 1]) {
      maxi++;
      for (int j = i + 1; j < s.size() - 1; ++j) {
        if (s[j] == s[j + 1]) {
          maxi++;
          break;
        }
      }
      break;
    }
  }
  cout << maxi;
  return 0;
}
