#include <bits/stdc++.h>
using namespace std;
int dx[4] = {0, 0, 1, -1};
int dy[4] = {1, -1, 0, 0};
const int N = 1e5 + 5, NN = 10, mod = 1e8;
int n;
string s;
int mem[N][4][2][2];
int solve(int pos, int l, int st, int en) {
  if (pos == n) return 0;
  int &ret = mem[pos][l][st][en];
  if (~ret) return ret;
  int x = s[pos] - '0';
  if (st && !en) x ^= 1;
  if (!st || (st && en)) {
    ret = (l != x) + solve(pos + 1, x, st, en);
    if (!st) {
      x ^= 1;
      ret = max(ret, (x != l) + solve(pos + 1, x, 1, 0));
      ret = max(ret, (x != l) + solve(pos + 1, x, 1, 1));
    }
  }
  if (st && !en) {
    ret = max(ret, (l != x) + solve(pos + 1, x, 1, 0));
    ret = max(ret, (l != x) + solve(pos + 1, x, 1, 1));
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> s;
  memset(mem, -1, sizeof mem);
  cout << solve(0, 2, 0, 0);
}
