#include <bits/stdc++.h>

#define debug(x) cerr << #x << " = " << x << endl

using namespace std;
typedef long long LL;

const int MAXN = 2e5 + 100;
const int MOD = 1E9 + 7;
int n;
char c[MAXN];

template <class T>
void read(T& x) {
    x = 0;
    T f = 1;
    char ch = getchar();
    while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar();
    while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar();
    x *= f;
}

template <class T, class... Args>
void read(T& x, Args&... args) {
    read(x), read(args...);
}

template <class T>
void write(T x) {
    if (x < 0) putchar('-'), x = -x;
    if (x > 9) write(x / 10);
    putchar(x % 10 + '0');
}

LL qpow(LL a, LL b, LL MOD) {
    LL ans = 1, base = a;
    while (b) {
        if (b & 1) ans = ans * base % MOD;
        b >>= 1, base = base * base % MOD;
    }
    return ans;
}

void solve(int testNum) {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> c[i];
    for (int i = 1; i <= n; i++) {
        if (c[i] == '0') {
            if (i + 1 <= n && c[i + 1] != '1') {
                cout << 0;
                return;
            }
            if (i + 2 <= n && c[i + 2] != '1') {
                cout << 0;
                return;
            }
            if (i + 3 <= n && c[i + 3] != '0') {
                cout << 0;
                return;
            }
        } else {
            if (i + 1 <= n) {
                if (c[i + 1] == '0') {
                    if (i + 2 <= n && c[i + 2] != '1') {
                        cout << 0;
                        return;
                    }
                    if (i + 3 <= n && c[i + 3] != '1') {
                        cout << 0;
                        return;
                    }
                } else {
                    if (i + 2 <= n && c[i + 2] != '0') {
                        cout << 0;
                        return;
                    }
                    if (i + 3 <= n && c[i + 3] != '1') {
                        cout << 0;
                        return;
                    }
                }
            }
        }
    }
    if (n == 1) {
        if (c[1] == '1')
            cout << 2ll * (LL)pow(10ll, 10);
        else
            cout << (LL)pow(10ll, 10);
        return;
    }
    if (c[1] == '1' && c[2] == '1')
        cout << (LL)ceil(((LL)pow(10ll, 10) * 3 - (n - 1)) / 3.0);
    else if (c[1] == '1' && c[2] == '0')
        cout << (LL)ceil(((LL)pow(10ll, 10) * 3 - 1 - (n - 1)) / 3.0);
    else
        cout << (LL)ceil(((LL)pow(10ll, 10) * 3 - 2 - (n - 1)) / 3.0);
}

signed main() {
    // freopen("1.in", "r", stdin);
    int testCase = 1;
    // read(testCase);
    // ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    // cin >> testCase;
    for (int i = 1; i <= testCase; i++) solve(i);
    return 0;
}
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
int main(){
  ll n,ans,i,j;
  string t;
  cin>>n>>t;
  if(n==1){
    if(t[0]=='0') ans=1e10;
    else if(t[0]=='1') ans=2e10;
  }
  else if(n==2){
    if(t=="00") ans=0;
    else if(t=="01") ans=1e10-1;
    else ans=1e10;
  }
  else if(n==3){
    if(t=="110") ans=1e10;
    else if(t=="011"||t=="101") ans=1e10-1;
    else ans=0;
  }
  else if(n==4){
    if(t=="1101"||t=="1011"||t=="0110") ans=1e10-1;
    else ans=0;
  }
  else{
    i=0;
    while(i<3&&(t[i]!='1'||t[i+1]!='1'||t[i+2]!='0')) i++;
    if(i>2) ans=0;
    else if(i==0){
      j=3;
      while(j<n/3*3&&t[j]=='1'&&t[j+1]=='1'&&t[j+2]=='0') j+=3;
      if(j<n/3*3) ans=0;
      else if(n%3==0) ans=1e10-n/3+1;
      else if(n%3==1){
        if(t[n-1]!='1') ans=0;
        else if(t[n-1]=='1') ans=1e10-n/3;
      }
      else if(n%3==2){
        if(t[n-2]!='1'||t[n-1]!='1') ans=0;
        else ans=1e10-n/3;
      }
    }
    else if(i==1){
      if(t[0]!='0') ans=0;
      else{
        j=4;
        while(j<n-2&&t[j]=='1'&&t[j+1]=='1'&&t[j+2]=='0') j+=3;
        if(j<n-2) ans=0;
        else if(n%3==1) ans=1e10-n/3;
        else if(n%3==2){
          if(t[n-1]!='1') ans=0;
          else if(t[n-1]=='1') ans=1e10-n/3-1;
        }
        else if(n%3==0){
          if(t[n-2]!='1'||t[n-1]!='1') ans=0;
          else ans=1e10-n/3;
        }
      }
    }
    else if(i==2){
      if(t[0]!='1'||t[1]!='0') ans=0;
      else{
        j=5;
        while(j<n-2&&t[j]=='1'&&t[j+1]=='1'&&t[j+2]=='0') j+=3;
        if(j<n-2) ans=0;
        else if(n%3==2) ans=1e10-n/3;
        else if(n%3==0){
          if(t[n-1]!='1') ans=0;
          else if(t[n-1]=='1') ans=1e10-n/3;
        }
        else if(n%3==1){
          if(t[n-2]!='1'||t[n-1]!='1') ans=0;
          else ans=1e10-n/3;
        }
      }
    }
  }
  cout<<ans<<endl;
}