#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  if (n == 1) {
    cout << 1 << "\n";
    return 0;
  }
  if (n <= 3) {
    cout << n << "\n";
    return 0;
  }
  vector<int> tab[2];
  int arr[100010];
  for (int i = 0; i < n; i++) arr[i] = (s[i] == '1');
  int i = 0;
  bool ada = false;
  while (i < s.length()) {
    int count = 1;
    char ingat = s[i];
    while (s[i + 1] == s[i]) {
      ++count;
      ++i;
    }
    ++i;
    if (count >= 3) ada = true;
    tab[ingat - '0'].push_back(count);
  }
  if (tab[0].size() + tab[1].size() == n)
    cout << n << "\n";
  else {
    int optimal[100010];
    for (int i = 0; i < n; i++) optimal[i] = i % 2;
    int i = 0;
    bool ada1 = false;
    bool ada2 = false;
    bool ada3 = false;
    bool ada4 = false;
    while (i < n) {
      int start = i;
      while (arr[i] != optimal[i]) ++i;
      int end = i - 1;
      if (end < start) {
        ++i;
        continue;
      }
      if (start == 0 && arr[end + 1] == arr[end]) {
        ada1 = true;
      } else if (end == n - 1 && arr[start - 1] == arr[start]) {
        ada1 = true;
      } else if (arr[start - 1] == arr[start] && arr[end + 1] == arr[end]) {
        ada2 = true;
      }
    }
    for (int i = 0; i < n; i++) optimal[i] = (i % 2 == 0);
    i = 0;
    while (i < n) {
      int start = i;
      while (arr[i] != optimal[i]) ++i;
      int end = i - 1;
      if (end < start) {
        ++i;
        continue;
      }
      if (start == 0 && arr[end + 1] == arr[end]) {
        ada3 = true;
      } else if (end == n - 1 && arr[start - 1] == arr[start]) {
        ada3 = true;
      } else if (arr[start - 1] == arr[start] && arr[end + 1] == arr[end]) {
        ada4 = true;
      }
    }
    if (ada2 || ada4)
      cout << tab[0].size() + tab[1].size() + 2 << "\n";
    else if (ada1 || ada3)
      cout << tab[0].size() + tab[1].size() + 1 << "\n";
    else
      cout << tab[0].size() + tab[1].size() << "\n";
  }
}
