#include <bits/stdc++.h>
using namespace std;
const int MX = 123456;
long long md = 1e9 + 7;
long long N;
long long dp[MX][5][5][5];
string s;
int cnt = 0;
long long f(long long i, long long last, long long act, long long once) {
  if (i == s.size()) return 0;
  long long &ret = dp[i][last][act][once];
  if (ret != -1) return ret;
  ret = 0;
  long long cur = s[i] - '0';
  if (once) {
    if (cur == last) {
      ret = max(ret, 1 + f(i + 1, !cur, 1, 0));
      ret = max(ret, f(i + 1, last, 1, 0));
      ret = max(ret, f(i + 1, last, act, 1));
    } else if (cur != last) {
      ret = max(ret, f(i + 1, last, 1, 0));
      ret = max(ret, 1 + f(i + 1, cur, act, 1));
      ret = max(ret, f(i + 1, last, 1, 0));
    }
  }
  ret = max(ret, f(i + 1, last, act, once));
  if (act == 1) {
    if (cur == last) ret = max(ret, f(i + 1, last, 0, once));
    if (cur != last) {
      ret = max(ret, 1 + f(i + 1, cur, 0, once));
    }
    if (cur == last) ret = max(ret, 1 + f(i + 1, !cur, act, once));
  } else if (act == 0) {
    if (cur != last) ret = max(ret, 1 + f(i + 1, cur, act, once));
  }
  return ret;
}
int main() {
  cin >> N;
  cin >> s;
  memset(dp, -1, sizeof dp);
  cout << f(0, 3, 0, 1) << "\n";
  return 0;
}
