#include <bits/stdc++.h>
using namespace std;
int n;
string cad;
int mem[5][111111][5];
int go(int prev, int pos, int ch) {
  if (pos == n) return 0;
  int &r = mem[prev][pos][ch];
  if (r != -1) return r;
  r = go(prev, pos + 1, ch);
  int curr = cad[pos] - '0';
  if (ch == 1) curr = 1 - curr;
  r = max(r, go(curr, pos + 1, ch) + (curr != prev));
  if (ch < 2) r = max(r, go(prev, pos, ch + 1));
  return r;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  memset(mem, -1, sizeof(mem));
  cin >> n >> cad;
  cout << go(2, 0, 0) << '\n';
  return 0;
}
