#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  int n;
  string s;
  cin >> n;
  cin >> s;
  int ans = 1;
  int k = 0;
  for (int i = 1; i < n; ++i)
    if (s[i] == s[i - 1])
      k++;
    else
      ans++;
  if (k == 1) ans++;
  if (k > 1) ans += 2;
  cout << ans;
}
