#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  vector<int> arr(n);
  int zero = 0, one = 0;
  for (int i = n - 1; i > -1; i--) {
    if (s[i] == '0') {
      arr[i] = one + 1;
      zero = arr[i];
    } else {
      arr[i] = zero + 1;
      one = arr[i];
    }
  }
  int i = 1, j = n - 2;
  while (s[i] != s[i - 1] && i < n) i++;
  while (s[j] != s[j + 1] && j > -1) j--;
  if (i - j == 1)
    cout << arr[0] + 1 << endl;
  else if (i < n && j > -1)
    cout << arr[0] + 2 << endl;
  else
    cout << arr[0] << endl;
}
