#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  int dp[2][n];
  memset(dp, 0, sizeof(dp));
  int f = true;
  for (int i = 0; i < n; i++) {
    if (i - 2 < 0 || i + 1 >= n) continue;
    if (s[i] != s[i - 1] && s[i] != s[i - 2] && s[i] == s[i + 1]) {
      s[i] = ('1' - s[i]) + '0';
      s[i - 1] = ('1' - s[i - 1]) + '0';
      f = false;
      break;
    }
  }
  if (f == true)
    for (int i = 0; i < n; i++) {
      if (i - 1 < 0 || i + 1 >= n) continue;
      if (s[i] == s[i - 1] && s[i] == s[i + 1]) {
        s[i] = ('1' - s[i]) + '0';
        f = false;
        break;
      }
    }
  if (f)
    for (int i = 0; i < n; i++) {
      if (i - 1 < 0 || i + 1 >= n) continue;
      if (s[i] == s[i - 1]) {
        int j = i + 1;
        for (; j < n - 1; j++) {
          if (s[j] == s[j + 1]) break;
        }
        for (; i <= j; i++) s[i] = ('1' - s[i]) + '0';
        f = false;
        break;
      }
    }
  if (f)
    for (int i = 1; i < n; i++) {
      if (s[i] == s[i - 1]) s[i] = ('1' - s[i]) + '0';
    }
  if (s[0] == '0')
    dp[1][0] = 1;
  else
    dp[0][0] = 1;
  for (int i = 1; i < n; i++) {
    if (s[i] == '1') {
      dp[0][i] = max(dp[0][i - 1], dp[1][i - 1] + 1);
      dp[1][i] = dp[1][i - 1];
    } else {
      dp[1][i] = max(dp[1][i - 1], dp[0][i - 1] + 1);
      dp[0][i] = dp[0][i - 1];
    }
  }
  cout << max(dp[0][n - 1], dp[1][n - 1]) << endl;
}
