#include <bits/stdc++.h>
using namespace std;
int const N = 1e5 + 5;
int a[N];
int memo[N][3][3];
int n;
int dp(int i, int k, int last) {
  if (k > 2) return -1 * N;
  if (i == n) return 0;
  int &ret = memo[i][k][last];
  if (ret != -1) return ret;
  return ret = max(dp(i, k + 1, last),
                   dp(i + 1, k, (a[i] ^ (k == 1) ? 1 : 0)) +
                       ((last != (a[i] ^ (k == 1) ? 1 : 0)) ? 1 : 0));
}
void solve() {
  memset(memo, -1, sizeof(memo));
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < n; i++)
    if (s[i] == '1') a[i] = 1;
  int ans = dp(0, 0, 2);
  cout << ans << endl;
}
int main() {
  solve();
  return 0;
}
