#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, sum = 1, d = 0, y = 0;
  cin >> n;
  string a;
  cin >> a;
  for (int i = 0; i <= n - 2; i++) {
    if (a[i] != a[i + 1]) sum++;
  }
  if (sum == n || sum == (n - 1))
    cout << n;
  else {
    for (int i = 1; i <= n - 3; i++) {
      if (a[i] == a[i + 1]) {
        sum += 2;
        cout << sum;
        y = 1;
        break;
      }
    }
    if (y != 1) {
      if (a[0] == a[1]) sum++;
      if (a[n - 2] == a[n - 1]) sum++;
      cout << sum;
    }
  }
  return 0;
}
