#include <bits/stdc++.h>
using namespace std;
const long long int N = 1e5 + 1000;
long long int dp[N], n, ans, cnt = 1, mx;
string s;
int main() {
  cin >> n >> s;
  dp[0] = 1;
  for (int i = 1; i < n; i++) {
    dp[i] = dp[i - 1];
    dp[i] += (s[i] != s[i - 1]);
    if (s[i] == s[i - 1]) {
      cnt++;
      if (cnt > 1) ans++;
    } else
      cnt = 1;
    mx = max(cnt, mx);
  }
  if (ans == 1 && mx == 2) {
    cout << n << '\n';
    return 0;
  }
  if (mx > 2 || ans > 1)
    cout << dp[n - 1] + 2;
  else
    cout << dp[n - 1];
  return 0;
}
