#include <bits/stdc++.h>
using namespace std;
int a[100010], a1[2][100010], a2[2][100010];
int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < n; i++) a[i + 1] = s[i] - '0';
  for (int i = 1; i <= n; i++) {
    a1[1][i] = a1[1][i - 1];
    a1[0][i] = a1[0][i - 1];
    if (a[i] == 1)
      a1[1][i] = a1[0][i - 1] + 1;
    else
      a1[0][i] = a1[1][i - 1] + 1;
  }
  for (int i = n; i >= 1; i--) {
    a2[1][i] = a2[1][i + 1];
    a2[0][i] = a2[0][i + 1];
    if (a[i] == 1)
      a2[1][i] = a2[0][i + 1] + 1;
    else
      a2[0][i] = a2[1][i + 1] + 1;
  }
  int ans = max(a1[0][n], a2[1][n]);
  int st = 1;
  int cur = 1;
  a[n + 1] = a[n];
  for (int i = 2; i <= n + 1; i++) {
    if (a[i] != a[i - 1])
      cur++;
    else {
      ans = max(ans, a1[a[st]][st - 1] + cur + a2[a[i - 1]][i]);
      st = i;
      cur = 1;
    }
  }
  cout << ans << endl;
}
