#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10, mod = 1e9 + 7, INF = 0x3f3f3f3f;
char s[maxn];
int main() {
  int n;
  cin >> n;
  scanf("%s", s + 1);
  int res = 1;
  for (int i = 2; i <= n; ++i) res += s[i] != s[i - 1];
  int ans = res;
  int cnt2 = 0, cnt3 = 0;
  for (int i = 1, j = 1; i <= n; i = j) {
    while (j <= n && s[i] == s[j]) ++j;
    if (j - i == 2) cnt2++;
    if (j - i > 2) cnt3++;
  }
  if (cnt2) ans = max(ans, res + 1);
  if (cnt3) ans = max(ans, res + 2);
  if (cnt2 > 1) ans = max(ans, res + 2);
  cout << ans;
  return 0;
}
