#include <bits/stdc++.h>
using namespace std;
long long inf = 1e18;
long long mod = 1e9 + 7;
long long delta = 10289;
const long long M = 320;
long long dp[M * M][M];
long long a[M * M];
int main() {
  long long n;
  cin >> n;
  char c, v;
  cin >> v;
  long long a = 0, b = 0;
  for (long long i = 1; i < n; i++) {
    cin >> c;
    a += (c == v);
    b += (c != v);
    v = c;
  }
  cout << 1 + b + min((long long)2, a);
}
