#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin >> s;
    if(n == 1){
        if(s == "0"){
            cout << 10000000000LL << endl;
        }else{
            cout << 20000000000LL << endl;
        }
        return 0;
    }
    if(n == 2){
        if(s == "11") cout << 10000000000LL << endl;
        else if(s == "10") cout << 10000000000LL << endl;
        else if(s == "01") cout << 9999999999LL << endl;
        else cout << 0 << endl;

        return 0;
    }
    int cas;
    if(s[0] == '0') cas = 0;
    else if(s[1] == '0') cas = 1;
    else cas = 2;

    if(cas == 0){
        s = s.substr(1, n - 1);
        n--;
        string t = "110";
        bool ok = true;
        for(int i=0;i<n;i++){
            if(s[i] != t[i%3]) ok = false;
        }
        n = (n + 2) / 3;
        cout << (ok ? 10000000000LL - n : 0) << endl;
        return 0;
    }else if(cas == 1){
        s = s.substr(2, n - 2);
        n -= 2;
        string t = "110";
        bool ok = true;
        for(int i=0;i<n;i++){
            if(s[i] != t[i%3]) ok = false;
        }
        n = (n + 2) / 3;
        cout << (ok ? 10000000000LL - n : 0) << endl;
        return 0;
    }else{
        if(s[2] == '1'){
            cout << 0 << endl;
            return 0;
        }
        s = s.substr(3, n - 3);
        n -= 3;
        string t = "110";
        bool ok = true;
        for(int i=0;i<n;i++){
            if(s[i] != t[i%3]) ok = false;
        }
        n = (n + 2) / 3;
        cout << (ok ? 10000000000LL - n : 0) << endl;
    }
    return 0;
}



#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         cout<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define endl            "\n"
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());


void __print(int32_t x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
char myHeap[200 * 1024 * 1024];
int sz = 0;
void assert_tle(bool q) { while (!q); }
void* operator new  ( std::size_t count ) {
    sz += count;
    assert_tle(sz <= 200 * 1024 * 1024);
    return myHeap + sz - count;
}
 
void operator delete (void *ptr) { }
 
 
void fastIO()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

void solve()
{
    int n;
    cin>>n;
    string str;
    cin>>str;

    string s="110";


    int i=0;
    bool started=false;

    string comp;

    while(comp.length()<=n+5)
    {
        comp.pb('1');
        comp.pb('1');
        comp.pb('0');
    }
    int lim=pow(10ll,10);
    lim*=3;
    lim--;
    int endpt=lim+3;
    // if(str=="0")
    // {
    //     cout<<pow(10ll,10);
    //     return;
    // }
    if(str=="1")
    {
        
        int ret=2*pow(10ll,10);
        cout<<ret;
        return;
    }
    if(comp.substr(0,n)==str)
    {
        endpt=n-1;
    }
    if(comp.substr(1,n)==str)
    {
        endpt=n;
    }
    if(comp.substr(2,n)==str)
    {
        endpt=n+1;
    }
    int ans=1;
    ans=(lim-endpt)/3;
    ans++;
    cout<<ans;

}
 
int32_t main()
{
    fastIO();
    //w(t)
    {
        solve();
        cout<<endl;
    }
    return 0;
}