#include <bits/stdc++.h>
using namespace std;
char str[100005];
int dp[100005][2][2];
int main() {
  int n;
  while (cin >> n) {
    cin >> str;
    memset(dp, -1, sizeof(dp));
    dp[0][0][0] = 1;
    dp[0][0][1] = -1;
    dp[0][1][1] = 1;
    dp[0][1][0] = -1;
    for (int i = 1; i < n; i++) {
      if (str[i] == str[i - 1]) {
        dp[i][0][0] = dp[i - 1][0][0];
        dp[i][0][1] = dp[i - 1][0][1];
        if (dp[i - 1][1][1] != -1) {
          dp[i][0][1] = max(dp[i][0][1], dp[i - 1][1][1] + 1);
        }
        dp[i][1][1] = dp[i - 1][0][0] + 1;
        if (dp[i - 1][1][1] != -1) {
          dp[i][1][1] = max(dp[i][1][1], dp[i - 1][1][1]);
        }
      } else {
        dp[i][0][0] = dp[i - 1][0][0] + 1;
        dp[i][0][1] = dp[i - 1][0][1] + 1;
        if (dp[i - 1][1][1] != -1)
          dp[i][0][1] = max(dp[i][0][1], dp[i - 1][1][1]);
        dp[i][1][1] = dp[i - 1][0][0];
        if (dp[i - 1][1][1] != -1)
          dp[i][1][1] = max(dp[i][1][1], dp[i - 1][1][1] + 1);
      }
    }
    int ans = dp[n - 1][0][0];
    ans = max(ans, dp[n - 1][0][1]);
    ans = max(ans, dp[n - 1][1][1]);
    printf("%d\n", ans);
  }
  return 0;
}
