#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 1, INF = 1e17, MOD = 1e9 + 7;
long long n, ans, cnt, t;
string s;
vector<long long> v;
long long ch(char a) { return (long long)a - 48; }
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> s;
  if (s[0] == '0')
    ans++, t++;
  else
    ans++;
  ++cnt;
  for (long long i = 1; i < n; ++i) {
    if (ch(s[i]) == t) {
      t += 1;
      t %= 2;
      ans++;
    }
    if (s[i] == s[i - 1]) {
      cnt++;
    } else {
      v.push_back(cnt);
      cnt = 1;
    }
  }
  v.push_back(cnt);
  sort(v.begin(), v.end());
  if (v.back() >= 3) {
    cout << ans + 2 << endl;
  } else {
    if (v.back() >= 2) {
      v.pop_back();
      if (!v.size()) return cout << ans + 1 << endl, 0;
      if (v.back() >= 2) {
        cout << ans + 2 << endl;
      } else {
        cout << ans + 1 << endl;
      }
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}
