#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;


int main() {
  long long n; cin >> n;
  string t; cin >> t;
  if (t == "1") {cout << 20000000000 << endl; return 0;}
  long long ans = 10000000000;
  for (int i = 1; i < n; ++i){
    if (t[i-1] == '0' && t[i] == '1') ans--;
  }
  string a, b, c;
  rep(i,n){
    if (i % 3 == 0) a.insert(a.begin(), '0');
    if (i % 3 == 0) b.insert(b.begin(), '1');
    if (i % 3 == 0) c.insert(c.begin(), '1');
    if (i % 3 == 1) a.insert(a.begin(), '1');
    if (i % 3 == 1) b.insert(b.begin(), '0');
    if (i % 3 == 1) c.insert(c.begin(), '1');
    if (i % 3 == 2) a.insert(a.begin(), '1');
    if (i % 3 == 2) b.insert(b.begin(), '1');
    if (i % 3 == 2) c.insert(c.begin(), '0');
  }
  if (t != a && t != b && t != c) {cout << 0 << endl; return 0;}
// cout << t << endl << a << endl << b << endl << c << endl; 
  cout << ans << endl;
}

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

bool check_cons_zeros(string t) {
  int cons_zeros = 0;
  for (auto &c : t) {
    if (c == '0') {
      cons_zeros++;
    } else {
      cons_zeros = 0;
    }
    if (cons_zeros > 1) {
      return true;
    }
  }
  return false;
}

bool check_cons_ones(string t) {
  int cons_ones = 0;
  for (auto &c : t) {
    if (c == '1') {
      cons_ones++;
    } else {
      cons_ones = 0;
    }
    if (cons_ones > 2) {
      return true;
    }
  }
  return false;
}

bool check_one_surr(string t) {
  for (int i = 1; i < t.length() - 1; i++) {
    if (t[i] == '1' && t[i - 1] == '0' && t[i + 1] == '0') {
      return true;
    }
  }
  return false;
}

int main() {
  _upgrade;
  int n;
  cin >> n;
  string t;
  cin >> t;
  if (check_cons_zeros(t) || check_cons_ones(t) || check_one_surr(t)) {
    // cerr << check_cons_zeros(t) << "\n";
    // cerr << check_cons_ones(t) << "\n";
    // cerr << check_one_surr(t) << "\n";
    cout << 0 << "\n";
    return 0;
  }
  long long res = 1e10;  // change
  if (t.length() == 1) {
    if (t[0] == '0') {
      cout << res << "\n";
    } else {
      cout << 2 * res << "\n";
    }
  } else {
    if (t[0] == '1' && t[1] == '1') {
      cout << res - (t.length() + 2) / 3 + 1 << "\n";
    } else if (t[0] == '1' && t[1] == '0') {
      long long need = 1 + (t.length() - 2 + 2) / 3;
      cout << res - (need - 1) << "\n";
    } else {
      long long need = 1 + (t.length() - 1 + 2) / 3;
      cout << res - (need - 1) << "\n";
    }
  }
  return 0;
}