#include <bits/stdc++.h>
using namespace std;
int n, cnt, dbl;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> s;
  cnt = 1;
  for (int i = 1; i < n; ++i) {
    if (s[i] != s[i - 1])
      ++cnt;
    else {
      ++dbl;
    }
  }
  if (dbl >= 2)
    cout << cnt + 2;
  else if (dbl >= 1)
    cout << cnt + 1;
  else
    cout << cnt;
}
