#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
const int MOD = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int ans = 1, cnt = 0;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1])
      ans++;
    else
      cnt++;
  }
  if (cnt == 1) ans++;
  if (cnt >= 2) ans += 2;
  cout << ans;
  return 0;
}
