#include <bits/stdc++.h>
using namespace std;
const int N = 100005, OO = 0x3f3f3f3f;
long long x, c, n, a, n2;
bitset<N> isprime;
vector<int> v;
string s;
int mem[N][2][2][2];
int solve(int i, bool ch, bool ch2, bool pr) {
  if (i == n) return 0;
  int &ret = mem[i][ch][pr][ch2];
  if (ret != -1) return ret;
  int op1 = 0;
  if (pr != s[i] - '0')
    op1 = max(op1, solve(i + 1, ch, ch ? 1 : 0, s[i] - '0') + 1);
  else {
    if (!ch || !ch2)
      op1 = max(op1, solve(i + 1, 1, 0, '1' - s[i]) + (('1' - s[i]) != pr));
    op1 = max(op1, solve(i + 1, ch, 1, pr));
  }
  return ret = op1;
}
int main() {
  memset(mem, -1, sizeof mem);
  cin >> n;
  cin >> s;
  cout << solve(0, 0, 0, '1' - s[0]);
  return 0;
}
