#include <bits/stdc++.h>
using namespace std;
int sum[100005];
int main() {
  int n, hold, left, right;
  cin >> n;
  string g, sub;
  cin >> g;
  hold = g.size();
  sum[0] = 1;
  for (int i = 1; i < g.size(); i++)
    sum[i] = (g[i - 1] == g[i]) ? sum[i - 1] : sum[i - 1] + 1;
  if (g.find("000") != string::npos || g.find("111") != string::npos)
    return printf("%d", sum[n - 1] + 2), 0;
  left = g.find("00");
  right = g.find("11");
  if (max(left, right) != string::npos) {
    if (min(left, right) == -1)
      hold = max(left, right);
    else
      hold = min(left, right);
    sub = g.substr(hold + 1, n - 1);
    left = sub.find("00");
    right = sub.find("11");
    if (max(left, right) != string::npos)
      return printf("%d", sum[n - 1] + 2), 0;
    else
      return printf("%d", sum[n - 1] + 1), 0;
  }
  printf("%d", sum[n - 1] + 0);
  return 0;
}
