#include <bits/stdc++.h>
const double EPS = 1e-10;
using namespace std;
inline int rit() {
  int f = 0, key = 1;
  char c;
  do {
    c = getchar();
    if (c == '-') key = -1;
  } while (c < '0' || c > '9');
  do {
    f = f * 10 + c - '0';
    c = getchar();
  } while (c >= '0' && c <= '9');
  return f * key;
}
int n;
void init() {}
const int Z = 100005;
char a[Z];
void read() {
  int i;
  n = rit();
  for (i = 0; i < n; i++) {
    scanf(" %c", &a[i]);
  }
}
int ans;
void calc() {
  int i, key, cnt;
  key = '0';
  for (i = cnt = 0; i < n; i++) {
    if (a[i] == key) {
      cnt++;
      key = (key == '0' ? '1' : '0');
    }
  }
  ans = cnt;
  key = '1';
  for (i = cnt = 0; i < n; i++) {
    if (a[i] == key) {
      cnt++;
      key = (key == '0' ? '1' : '0');
    }
  }
  ans = max(ans, cnt);
  return;
}
void solve() {
  int L, R, i;
  L = n * 10;
  R = -10;
  calc();
  for (L = 0; L < n - 1; L++) {
    if (a[L] == a[L + 1]) break;
  }
  for (R = n - 1; R > 0; R--) {
    if (a[R] == a[R - 1]) break;
  }
  R--;
  L++;
  if (L <= R)
    cout << ans + 2 << endl;
  else if (L == R + 1)
    cout << ans + 1 << endl;
  else
    cout << ans << endl;
}
int main() {
  int nn = 1;
  init();
  while (nn--) {
    read();
    solve();
  }
  return 0;
}
