#include <bits/stdc++.h>
using namespace std;
int a[100001][3];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  a[n - 1][0] = 1;
  a[n - 1][1] = 0;
  a[n - 1][2] = 0;
  int b0 = -1, b1 = -1;
  if (s[n - 1] == '0')
    b0 = n - 1;
  else
    b1 = n - 1;
  for (int m = n - 2; m >= 0; --m) {
    if (s[m + 1] == '0')
      b0 = m + 1;
    else
      b1 = m + 1;
    a[m][0] = 1;
    a[m][1] = 0;
    a[m][2] = 0;
    if (s[m] == '0') {
      if (b1 != -1) {
        a[m][0] = a[b1][0] + 1;
        a[m][2] = a[b1][2] + 1;
        a[m][1] = a[b1][1] + 1;
      }
      if (b0 != -1) {
        a[m][1] = max(a[m][1], a[b0][0] + 1);
        a[m][2] = max(a[m][2], a[b0][1] + 1);
      }
    } else {
      if (b0 != -1) {
        a[m][0] = a[b0][0] + 1;
        a[m][2] = a[b0][2] + 1;
        a[m][1] = a[b0][1] + 1;
      }
      if (b1 != -1) {
        a[m][1] = max(a[m][1], a[b1][0] + 1);
        a[m][2] = max(a[m][2], a[b1][1] + 1);
      }
    }
  }
  int ans = max(max(a[0][0], a[0][1]), a[0][2]);
  cout << ans << endl;
}
