#include <bits/stdc++.h>
using namespace std;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
long long mod = 1000000007;
long long mod_v(long long nn) { return nn % mod; }
template <class T>
T fast_pow(T n, T p) {
  if (p == 0) return 1;
  if (p % 2) {
    T g = mod_v(mod_v(n) * mod_v(fast_pow(n, p - 1)));
    return g;
  } else {
    T g = fast_pow(n, p / 2);
    g = mod_v(mod_v(g) * mod_v(g));
    return g;
  }
}
template <class T>
inline T modInverse(T n) {
  return fast_pow(n, mod - 2);
}
const int mxn = 111111;
int n, second[mxn];
char inp[mxn];
int main() {
  scanf("%d ", &n);
  scanf("%s", &inp);
  for (int i = 0; i < n; i++) {
    second[i] = (int)(inp[i] - '0');
  }
  int lft = 0;
  for (int i = 1; i < n; i++) {
    if (second[i] == second[i - 1]) {
      lft = i;
      break;
    }
  }
  int rgt = n - 1;
  for (int i = n - 2; i >= 0 && i >= lft; i--) {
    if (second[i] == second[i + 1]) {
      rgt = i;
      break;
    }
  }
  for (int i = lft; i <= rgt; i++) {
    second[i] += 1;
    second[i] %= 2;
  }
  int ans = 1;
  int bb = second[0];
  for (int i = 1; i < n; i++) {
    if (second[i] != bb) {
      ans++;
      bb = second[i];
    }
  }
  cout << ans << "\n";
  return 0;
}
