#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, m;
int dp[maxn][5];
char ss[maxn];
int main() {
  scanf("%d", &n);
  getchar();
  scanf("%s", ss + 1);
  for (int i = 1; i <= n; i++) {
    if (ss[i] == '0') {
      dp[i][0] = dp[i - 1][1] + 1;
      dp[i][1] = dp[i - 1][1];
    } else if (ss[i] == '1') {
      dp[i][0] = dp[i - 1][0];
      dp[i][1] = dp[i - 1][0] + 1;
    }
  }
  int ans = max(1, max(dp[n][0], dp[n][1]));
  int cnt1, cnt2, l1, l2;
  cnt1 = cnt2 = 0;
  for (int i = 1; i <= n; i++) {
    if (ss[i] == '0') {
      int tt = 0;
      for (int j = i; j <= n; j++) {
        if (ss[j] == '0') {
          tt++;
          if (j == n) {
            if (cnt1 < tt) {
              cnt1 = tt;
            }
          }
          i = i + tt;
        } else {
          if (cnt1 < tt) {
            cnt1 = tt;
          }
          i = j - 1;
          break;
        }
      }
    } else if (ss[i] == '1') {
      int tt = 0;
      for (int j = i; j <= n; j++) {
        if (ss[j] == '1') {
          tt++;
          if (j == n) {
            if (cnt2 < tt) {
              cnt2 = tt;
            }
          }
          i = i + tt;
        } else {
          if (cnt2 < tt) {
            cnt2 = tt;
          }
          i = j - 1;
          break;
        }
      }
    }
  }
  int maxx = max(cnt1, cnt2);
  if (maxx >= 2) {
    printf("%d\n", min(n, ans + 2));
  } else
    printf("%d\n", ans);
  return 0;
}
