#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 10;
int n, len, dp0, dp1;
char a[maxn];
int main() {
  cin >> n;
  scanf("%s", a);
  len = strlen(a);
  int ans = 0;
  if (a[0] == '0')
    dp0 = 1;
  else
    dp1 = 1;
  for (int i = 1; i < len; i++) {
    if (a[i] == '0')
      dp0 = dp1 + 1;
    else
      dp1 = dp0 + 1;
  }
  ans = max(dp0, dp1);
  int cnt0 = 0, cnt1 = 0;
  for (int i = 0; i < len; i++) {
    if (a[i] == '0' && a[i + 1] == '0')
      cnt0++;
    else if (a[i] == '1' && a[i + 1] == '1')
      cnt1++;
  }
  ans += min(2, cnt1 + cnt0);
  cout << ans;
  return 0;
}
