#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string a;
  cin >> n >> a;
  int D[n];
  D[0] = 1;
  for (int i = 1; i < n; i++) {
    if (a[i] != a[i - 1]) {
      D[i] = D[i - 1] + 1;
    } else {
      D[i] = D[i - 1];
    }
  }
  int ans = D[n - 1];
  cout << min(n, ans + 2);
}
