#include <bits/stdc++.h>
using namespace std;
int n;
string s;
int main(int argc, char const *argv[]) {
  cin >> n;
  cin >> s;
  int ans = 1;
  int state = 0;
  for (int i = 1; i < n; i++) {
    if (s[i] != s[i - 1])
      ans++;
    else if (state < 2)
      state++, ans++;
  }
  cout << ans << endl;
  return 0;
}
