#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000 * 1000 * 1000 + 7;
const double PI = 2 * acos(0);
char A[100002];
int main() {
  int N;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  int ans = 1;
  for (int i = 1; i < N; i++) {
    ans += (A[i] != A[i - 1]);
  }
  cout << min(N, ans + 2) << "\n";
}
