#include <bits/stdc++.h>
using namespace std;
int n;
char str[1000005];
class TMain {
 private:
 public:
  int run() {
    scanf("%d", &n);
    scanf("%s", str + 1);
    int ans = 1, flag = 0;
    for (int i = 2; i <= n; i++) {
      if (str[i] != str[i - 1]) {
        ans++;
      } else {
        flag++;
      }
    }
    printf("%d\n", ans + min(flag, 2));
    return 0;
  }
} Main;
int main() { return Main.run(); }
