#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point() {}
  point(int a, int b) { x = a, y = b; }
};
template <class T>
T sqr(T a) {
  return a * a;
}
template <class T>
T power(T n, T p) {
  T res = 1;
  for (int i = 0; i < p; i++) res *= n;
  return res;
}
template <class T>
double getdist(T a, T b) {
  return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
}
template <class T>
T extract(string s, T ret) {
  stringstream ss(s);
  ss >> ret;
  return ret;
}
template <class T>
string tostring(T n) {
  stringstream ss;
  ss << n;
  return ss.str();
}
struct fast {
  fast() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
  }
} cincout;
int dp[100010][3][2];
vector<int> arr;
int call(int indx, int status, int last) {
  if (indx == (int)(arr.size())) return status ? 1 : -(1 << 28);
  int &ret = dp[indx][status][last];
  if (ret != -1) return ret;
  ret = -(1 << 28);
  if (status == 2) {
    if (last == 0 && arr[indx] == 0)
      ret = max(ret, call(indx + 1, status, 0));
    else if (last == 0 && arr[indx] == 1)
      ret = max(ret, call(indx + 1, status, 1) + 1);
    else if (last == 1 && arr[indx] == 0)
      ret = max(ret, call(indx + 1, status, 0) + 1);
    else if (last == 1 && arr[indx] == 1)
      ret = max(ret, call(indx + 1, status, 1));
    return ret;
  }
  if (status == 0) {
    if (last == 0 && arr[indx] == 0) {
      ret = max(ret, call(indx + 1, 0, 0));
      ret = max(ret, call(indx + 1, 1, 1) + 1);
    } else if (last == 0 && arr[indx] == 1) {
      ret = max(ret, call(indx + 1, 0, 1) + 1);
      ret = max(ret, call(indx + 1, 1, 0));
    } else if (last == 1 && arr[indx] == 0) {
      ret = max(ret, call(indx + 1, 0, 0) + 1);
      ret = max(ret, call(indx + 1, 1, 1));
    } else if (last == 1 && arr[indx] == 1) {
      ret = max(ret, call(indx + 1, 0, 1));
      ret = max(ret, call(indx + 1, 1, 0) + 1);
    }
    return ret;
  }
  if (last == 0 && arr[indx] == 0) {
    ret = max(ret, call(indx + 1, 1, 1) + 1);
    ret = max(ret, call(indx + 1, 2, 0));
  } else if (last == 0 && arr[indx] == 1) {
    ret = max(ret, call(indx + 1, 1, 0));
    ret = max(ret, call(indx + 1, 2, 1) + 1);
  } else if (last == 1 && arr[indx] == 0) {
    ret = max(ret, call(indx + 1, 1, 1));
    ret = max(ret, call(indx + 1, 2, 0) + 1);
  } else if (last == 1 && arr[indx] == 1) {
    ret = max(ret, call(indx + 1, 1, 0) + 1);
    ret = max(ret, call(indx + 1, 2, 1));
  }
  return ret;
}
int main() {
  string s;
  cin >> s >> s;
  arr.resize((int)(s.size()));
  for (int i = 0; i < (int)(s.size()); i++) arr[i] = s[i] - '0';
  memset(dp, -1, sizeof dp);
  int res = 0;
  res = max(res, call(1, 0, arr[0]));
  res = max(res, call(1, 1, !arr[0]));
  cout << res;
  return 0;
}
