#include <bits/stdc++.h>
using namespace std;
const int Max1 = 1e5 + 4;
const int Max2 = 2e5 + 4;
const int Mod = 1e9 + 7;
void solve() {
  int n;
  cin >> n;
  vector<int> v(n);
  vector<int> ne;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    v[i] = s[i] - '0';
  }
  int ans = 0;
  for (int i = 0; i < n; i++) {
    ne.push_back(v[i]);
    int cmp = v[i];
    int count = 1;
    while (i + 1 < n && v[i + 1] == cmp) {
      i++;
      count++;
    }
    ans = max(ans, count);
  }
  if (ans < 2)
    cout << ne.size() << "\n";
  else if (ans == 2) {
    cout << min(int(ne.size()) + 2, n);
  } else
    cout << ne.size() + 2 << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
