#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int solve() {
  int n, ans{0}, n_flip{0};
  cin >> n;
  if (n <= 0) return ans;
  char a, b, c;
  cin >> a;
  --n;
  ++ans;
  if (n == 0) return ans;
  cin >> b;
  if (b != a)
    ++ans;
  else
    ++n_flip;
  --n;
  bool flip{true};
  while (n--) {
    cin >> c;
    if (c != b) {
      ++ans;
      flip = true;
    } else if (a == b)
      n_flip = 2;
    else if (flip && n_flip < 2) {
      ++n_flip;
      flip = false;
    }
    a = b;
    b = c;
  }
  return ans + n_flip;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << solve() << endl;
  return 0;
}
