#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (long long i = (s); i < (long long)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using Pll = pair<ll, ll>;

int main() { 
    ll n, slen = 10;
    rep(i, 9){
        slen *= 10;
    }
    cin >> n;
    string t;
    cin >> t;

    ll onecnt=0, res, firstone;
    bool appear = false, valid = true;
    rep(i, n){
        if(!appear&&t[i]=='1'){
            onecnt++;
        }else{
            if(!appear&&t[i]=='0'){
                appear = true;
                firstone = i;
                onecnt = 0;
            }else{
                if(t[i]=='1'){
                    onecnt++;
                }else{
                    if(onecnt!=2){
                        valid = false;
                        break;
                    }else{
                        onecnt = 0;
                    }
                }
            }
        }
        if(onecnt>2){
            valid = false;
            break;
        }
    }

    if(!valid){
        res = 0;
    }else{
        if(n==1){
            if(t[0]=='0'){
                res = slen;
            }else{
                res = 2LL * slen;
            }
        }else{
            if(t=="11"){
                res = slen;
            }else{
              res = (3LL * slen - n - 2LL + firstone) / 3LL + 1LL;
            }
        }
    }

    cout << res << endl;
    return 0; 
}
#include <bits/stdc++.h>
 
#define rep(i,n) for(ll i=0;i<n;++i)
#define rrep(i, n) for(ll i=n-1;i>=0;--i)
#define rep1(i, n) for(ll i=1; i<=n; ++i)
#define repitr(itr,mp) for(auto itr=mp.begin();itr!=mp.end();++itr)
#define ALL(a) (a).begin(),(a).end()

template<class T> void chmax(T &a, const T &b){if(a < b){a = b;}}
template<class T> void chmin(T &a, const T &b){if(a > b){a = b;}}

using namespace std;
using ll  = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;

const ll MOD  = 1e9 + 7;
const ll LINF = 1LL << 60;
const int INF = 1e9 + 7;
const double PI = 3.1415926535897932384626;

ll mod(ll a, ll m){return (a + m) % m;}

int main(){
    ll n;
    string t;
    cin >> n >> t;

    ll base = 1e10;

    if(n == 1){
        if(t == "0")cout << base << endl;
        else cout << 2 * base << endl;
        return 0;
    }
    else if(n == 2){
        if(t == "00")cout << 0;
        else {
            if(t[0] == '0')cout << (3*base - 2) / 3 << endl;
            else cout << base << endl;
        }

        return 0;
    }

    bool ok = true;
    rep(i, n-2){
        string subt = t.substr(i, 3);
        if(subt == "110" || subt == "101" || subt == "011")continue;

        ok = false;
    }

    ll ans = 0;
    if(ok){
        ans = 3 * base - max(0LL, n-3);
        if(t[0] == '0')ans -= 2;
        else if(t.substr(0, 2) == "10")ans -= 1;

        ans /= 3; 
    }

    cout << ans << endl;
}