#include <bits/stdc++.h>
using namespace std;
char a[100005];
int main() {
  int n;
  cin >> n >> a;
  int ans = 0;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) ans++;
  }
  ans += 3;
  if (ans > n) ans = n;
  cout << ans << endl;
  return 0;
}
