#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 10;
vector<int> a;
int ans = 0;
int main() {
  string s;
  int n;
  scanf("%d", &(n));
  ;
  cin >> s;
  int cur = s[0] - '0';
  int cnt = 1;
  for (int(i) = (1); (i) < (n); (i)++) {
    int now = s[i] - '0';
    if (now == cur)
      cnt++;
    else {
      a.push_back(cnt);
      cnt = 1;
      cur = now;
    }
  }
  if (cnt) a.push_back(cnt);
  cout << (min(n, (int)a.size() + 2)) << "\n";
  ;
}
