#include <bits/stdc++.h>
using namespace std;
struct __s {
  __s() {
    if (1) {
      ios_base::Init i;
      cin.sync_with_stdio(0);
      cin.tie(0);
    }
  }
  ~__s() {
    if (!1)
      fprintf(stderr, "Execution time: %.3lf s.\n",
              (double)clock() / CLOCKS_PER_SEC);
    long long n;
    cin >> n;
  }
} __S;
long long a[2];
long long dp[2][111111];
int main(void) {
  long long n;
  cin >> n;
  string s;
  cin >> s;
  for (long long i = 0; i < (long long)(n); i++) {
    a[s[i] - '0']++;
  }
  if (a[0] == 0 || a[1] == 0) {
    cout << min(n, 3LL) << '\n';
    return 0;
  }
  dp[0][0] = 1;
  for (long long i = 1; i < n; i++) {
    dp[0][i] = dp[0][i - 1] + (s[i] != s[i - 1]);
  }
  dp[1][n - 1] = 1;
  for (long long i = n - 2; i >= 0; i--) {
    dp[1][i] = dp[1][i + 1] + (s[i] != s[i + 1]);
  }
  long long l = 1;
  while (l < n && s[l - 1] != s[l]) l++;
  if (l == n) {
    cout << n << '\n';
    return 0;
  }
  long long ans = 0;
  for (long long i = l; i < n; i++) {
    s[i] = (s[i] == '0' ? '1' : '0');
    long long res = 1;
    res += dp[0][i - 1];
    res -= (s[i] == s[i - 1]);
    if (i + 1 < n) {
      res += dp[1][i + 1];
      res -= (s[i] == s[i + 1]);
    }
    dp[0][i] = dp[0][i - 1] + (s[i] != s[i - 1]);
    ans = max(ans, res);
  }
  cout << ans << '\n';
  return 0;
}
