#include <bits/stdc++.h>
using namespace std;
long long a[100006], b1[100005], b2[100005], b3[100005], n, k, first, ans, mx;
long long sum, l, r, ans1, ans2, ans3;
bool f;
string s, st;
char ch;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  cin >> ch;
  a[1] = 0;
  if (ch == '1') a[1] = 1;
  a[0] = 1000000007;
  for (int i = 2; i <= n; ++i) {
    cin >> ch;
    a[i] = 0;
    if (ch == '1') a[i] = 1;
    if (!f && a[i] == a[i - 1]) {
      f = true;
      l = i;
    }
  }
  if (!f) l = n + 1;
  f = false;
  for (int i = n - 1; i > 0; --i)
    if (!f && a[i] == a[i + 1]) {
      f = true;
      r = i;
      break;
    }
  for (int i = 1; i <= n; ++i) {
    if (i < l)
      b1[i] = a[i];
    else
      b1[i] = (a[i] ^ 1);
    if (i > r)
      b2[i] = a[i];
    else
      b2[i] = (a[i] ^ 1);
    if (i < l || i > r)
      b3[i] = a[i];
    else
      b3[i] = (a[i] ^ 1);
    if (i != 1) {
      if (b1[i] != b1[i - 1]) ++ans1;
      if (b2[i] != b2[i - 1]) ++ans2;
      if (b3[i] != b3[i - 1]) ++ans3;
    }
  }
  cout << max(ans1, max(ans2, ans3)) + 1;
}
