#include <bits/stdc++.h>
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
const double EPS = 1e-8;
using namespace std;
const int N = 100005;
char bin[N];
int dp[N][2][2];
int max(int a, int b, int c) { return max(a, max(b, c)); }
int main() {
  int n;
  while (cin >> n) {
    scanf("%s", &bin);
    dp[0][0][0] = dp[0][1][1] = 1;
    for (int i = 1; i < n; ++i) {
      if (bin[i] == bin[i - 1]) {
        dp[i][0][0] = dp[i - 1][0][0];
        dp[i][1][0] = max(dp[i - 1][1][0], dp[i - 1][1][1] + 1);
        dp[i][1][1] = max(dp[i - 1][0][0] + 1, dp[i - 1][1][1]);
      } else {
        dp[i][0][0] = dp[i - 1][0][0] + 1;
        dp[i][1][0] = max(dp[i - 1][1][0] + 1, dp[i - 1][1][1]);
        dp[i][1][1] = max(dp[i - 1][0][0], dp[i - 1][1][1] + 1);
      }
    }
    cout << max(dp[n - 1][1][0], dp[n - 1][1][1]) << endl;
  }
  return 0;
}
