#include <bits/stdc++.h>
using namespace std;
int check(int* arr, int n, int h) {
  vector<int> index, v2;
  int i = 0, last, ans = 0;
  while (i < n) {
    if (arr[i] == h) {
      last = h;
      index.push_back(i);
      ans = 1;
      i++;
      break;
    } else
      v2.push_back(i);
    i++;
  }
  while (i < n) {
    if (arr[i] + last == 1) {
      index.push_back(i);
      last = 1 - last;
      ans++;
    } else
      v2.push_back(i);
    i++;
  }
  if (index.size() == 0) return 1;
  if (ans == n) return ans;
  int temp = index[0];
  for (i = 1; i < index.size(); i++)
    temp = max(temp, index[i] - index[i - 1] - 1);
  temp = max(temp, n - index[(int)index.size() - 1]);
  if (temp >= 2)
    return ans + 2;
  else {
    bool g = false;
    if (v2.size() == 1) return n;
    for (int i = 1; i < v2.size(); i++) {
      if (v2[i] != v2[i - 1] + 1) {
        g = true;
        break;
      }
    }
    if (g) return ans + 2;
    return ans + 1;
  }
}
int main() {
  int n;
  scanf("%d", &n);
  char str[n + 1];
  int arr[n];
  scanf("%s", &str);
  for (int i = 0; i < n; i++) arr[i] = str[i] - '0';
  int temp = max(check(arr, n, 0), check(arr, n, 1));
  if (temp <= n)
    printf("%d\n", temp);
  else
    printf("%d\n", n);
}
