#include <bits/stdc++.h>
const long long MOD = 1e9 + 7;
const int MAX_N = 100000 + 100;
const long long INF = 1e18;
const long long delta = 10957;
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n == 1) return cout << 1, 0;
  int m = 0;
  int f = 0;
  for (int i = 0; i < n - 1; ++i) {
    int l = 1;
    if (s[i] == s[i + 1]) {
      while (s[i] == s[i + 1]) {
        l++;
        i++;
      }
    }
    if (l == 2)
      f++;
    else if (l > 2)
      f += 2;
    m++;
  }
  if (n > 1 and s[n - 1] != s[n - 2]) m++;
  if (m == 1 and n > 2) return cout << 3, 0;
  if (f > 1)
    m += 2;
  else if (f > 0)
    m++;
  cout << m;
  return 0;
}
