#include <bits/stdc++.h>
using namespace std;
int dp[100005][3];
int len[100005];
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  dp[0][0] = dp[0][1] = 1;
  for (int i = 1; i < s.length(); i++) {
    dp[i][0] = dp[i - 1][0] + (s[i] != s[i - 1]);
    dp[i][1] =
        (dp[i - 1][1] + (s[i - 1] != s[i]) > dp[i - 1][0] + (s[i - 1] == s[i]))
            ? dp[i - 1][1] + (s[i - 1] != s[i])
            : dp[i - 1][0] + (s[i - 1] == s[i]);
    dp[i][2] =
        (dp[i - 1][2] + (s[i] != s[i - 1]) > dp[i - 1][1] + (s[i] == s[i - 1]))
            ? dp[i - 1][2] + (s[i] != s[i - 1])
            : dp[i - 1][1] + (s[i] == s[i - 1]);
  }
  int ret = (dp[n - 1][2] > dp[n - 1][1]) ? dp[n - 1][2] : dp[n - 1][1];
  cout << ret << endl;
  return 0;
}
