#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i;
  char a[100000];
  int dp[100000][3];
  int nearest_same[100000];
  int nearest_op[100000];
  cin >> n;
  for (i = 0; i < n; ++i) cin >> a[i];
  int ans = 0;
  nearest_op[n - 1] = nearest_same[n - 1] = -1;
  for (i = n - 2; i >= 0; --i) {
    if (a[i] == a[i + 1]) {
      nearest_same[i] = i + 1;
      nearest_op[i] = nearest_op[i + 1];
    } else {
      nearest_op[i] = i + 1;
      nearest_same[i] = nearest_op[i + 1];
    }
  }
  for (int ch = 0; ch <= 2; ++ch) {
    for (i = n - 1; i >= 0; --i) {
      dp[i][ch] = 1;
      if (nearest_op[i] != -1) {
        dp[i][ch] = max(dp[i][ch], dp[nearest_op[i]][ch] + 1);
      }
      if (ch > 0 && nearest_same[i] != -1) {
        dp[i][ch] = max(dp[i][ch], dp[nearest_same[i]][ch - 1] + 1);
      }
      ans = max(ans, dp[i][ch]);
    }
  }
  cout << ans << endl;
  return 0;
}
