#include <bits/stdc++.h>
using namespace std;
long long dp[1000000][4];
int main() {
  long long n, i;
  string s;
  cin >> n;
  cin >> s;
  dp[0][0] = 1;
  dp[0][1] = 1;
  dp[0][2] = 1;
  for (i = 1; i < n; i++) {
    dp[i][0] = dp[i - 1][0] + (s[i] != s[i - 1]);
    dp[i][1] = max(dp[i - 1][0] + (s[i] == s[i - 1]),
                   dp[i - 1][1] + (s[i] != s[i - 1]));
    dp[i][2] = max(dp[i - 1][2] + (s[i] != s[i - 1]),
                   dp[i - 1][1] + (s[i] == s[i - 1]));
  }
  cout << max(dp[n - 1][0], max(dp[n - 1][1], dp[n - 1][2]));
  return 0;
}
