#include <bits/stdc++.h>
using namespace std;
int dp[105][3] = {0};
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  bool f = true;
  vector<pair<int, int>> ans;
  int o = 0, e = 0;
  if (s[0] == '0')
    f = true;
  else
    f = false;
  for (int i = 0; i < n; i++) {
    if (s[i] == '0') {
      o++;
      if (!f) ans.push_back(make_pair(1, e));
      e = 0;
      f = true;
    }
    if (s[i] == '1') {
      e++;
      if (f) ans.push_back(make_pair(0, o));
      o = 0;
      f = false;
    }
  }
  if (f)
    ans.push_back(make_pair(0, o));
  else
    ans.push_back(make_pair(1, e));
  int f1 = 0;
  int m = ans.size();
  cout << min(n, m + 2);
  return 0;
  for (int i = 0; i < ans.size(); i++) {
    if (ans[i].second >= 3) {
      cout << ans.size() + 2;
      return 0;
    } else if (i + 1 <= ans.size() - 1) {
      if (ans[i].second >= 2 && ans[i + 1].second >= 2) {
        cout << ans.size() + 2;
        return 0;
      }
      if (ans[i].second >= 2 && ans[i + 1].second >= 1) {
        f1 = 1;
      }
      if (ans[i].second >= 1 && ans[i + 1].second >= 2) {
        f1 = 1;
      }
    }
  }
}
