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