#include <bits/stdc++.h>
using namespace std;
const int maxn = 100100;
int n, f[maxn][3];
string s;
void test() {
  puts("[test]");
  for (int i = 0; i < n; i++) {
    printf("%d: %6d%6d%6d\n", i, f[i][0], f[i][1], f[i][2]);
  }
}
int main() {
  cin >> n >> s;
  f[0][0] = f[0][1] = f[0][2] = 1;
  for (int i = 1; i < n; i++) {
    f[i][0] = f[i - 1][0] + (s[i] != s[i - 1]);
    f[i][1] =
        max(f[i - 1][0] + (s[i] == s[i - 1]), f[i - 1][1] + (s[i] != s[i - 1]));
    f[i][2] =
        max(f[i - 1][1] + (s[i] == s[i - 1]), f[i - 1][2] + (s[i] != s[i - 1]));
  }
  cout << max(f[n - 1][0], max(f[n - 1][1], f[n - 1][2])) << endl;
  return 0;
}
