#include <bits/stdc++.h>
using namespace std;
int n, ans = 1, sum, cnt = 1;
string test;
string s;
int main() {
  cin >> n;
  cin >> s;
  if (n <= 3) {
    cout << n;
    return 0;
  }
  test[0] = s[0];
  for (int i = 1; i < n; i++) {
    if (s[i] != test[0]) {
      test = s[i];
      ans++;
      if (cnt < 3) {
        sum++;
      } else if (cnt >= 3) {
        sum += 2;
      }
      cnt = 1;
    } else if (s[i] == s[i - 1]) {
      cnt++;
    }
  }
  if (cnt > 1) {
    if (cnt >= 3) {
      sum += 2;
    }
    if (cnt < 3) {
      sum++;
    }
  }
  if (sum > 2) {
    sum = 2;
  }
  ans += sum;
  if (ans <= 3) {
    ans = 3;
  }
  if (ans > n) {
    ans = n;
  }
  cout << ans;
  return 0;
}
