#include <bits/stdc++.h>
using namespace std;
int dp[2001][2001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  string s;
  cin >> n >> s;
  int x = 1, c = s[0];
  int d = 0, dd = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] == c) {
      x++;
    } else {
      if (x == 2)
        d++;
      else if (x > 2)
        dd++;
      x = 1;
      c = s[i];
    }
  }
  if (x == 2)
    d++;
  else if (x > 2)
    dd++;
  int l = 1;
  for (int i = 1; i < n; i++)
    if (s[i] != s[i - 1]) l++;
  if (d > 1 || dd > 0)
    l += 2;
  else if (d > 0)
    l++;
  cout << l;
}
