#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll Max=3*1e10;
int main()
{
    int n;cin>>n;int i;ll m=9999999999;
    string s;cin>>s;
    string s1="";
    for(int i=1;i<=2*1e5;i++)
    {
        if(i%3==0)
            s1+='0';
        else
            s1+='1';
    }
    //cout<<s1<<endl;
    if(n==1)
    {
        if(s[0]=='1')
        {
            ll f=Max/3*2;
            cout<<f<<endl;
        }
        else
        {
            ll f=Max/3;
            cout<<f<<endl;
        }
    }
    else if(n==2)
    {
        if(s=="11")
        {
            ll f=Max/3;
            cout<<f<<endl;
        }
        else if(s=="00")
        cout<<"0"<<endl;
        else if(s=="10")
        {
            ll f=Max/3;
            cout<<f<<endl;
        }
        else
            cout<<m<<endl;
    }
    else if(n==3)
    {
        if(s=="000"||s=="111"||s=="001"||s=="100"||s=="010")
            cout<<"0"<<endl;
        else if(s=="011")
            cout<<"9999999999"<<endl;
        else if(s=="101")
            cout<<m<<endl;
        else
        {
            ll f=Max/3;
            cout<<f<<endl;
        }
    }
    else
    {
        int sum=0;
        for(i=0;i<n;i++)
        {
            if(s[i]!=s1[i])
                break;
        }
        if(i==n)
            sum++;
        for(i=0;i<n;i++)
        {
            if(s[i]!=s1[i+1])
                break;
        }
        if(i==n)
            sum++;
        for(i=0;i<n;i++)
        {
            if(s[i]!=s1[i+2])
                break;
        }
        if(i==n)
            sum++;
            //cout<<sum<<endl;
        if(sum==0)
            cout<<"0"<<endl;
        else
        {
            if(s[0]=='1')
            {
                if(s[1]=='1')
                {
                    if(n%3==1)
                        n+=2;
                    else if(n%3==2)
                        n+=1;
                    ll f=Max;
                    f-=n;
                    f/=3;
                        cout<<f+1<<endl;
                }
                else
                {
                    n+=1;
                    if(n%3==1)
                        n+=2;
                    else if(n%3==2)
                        n+=1;
                    ll f=Max;
                    f-=n;
                    f/=3;
                        cout<<f+1<<endl;
                }
            }
            else
            {
                    n+=2;
                    if(n%3==1)
                        n+=2;
                    else if(n%3==2)
                        n+=1;
                    ll f=Max;
                    f-=n;
                    f/=3;
                        cout<<f+1<<endl;
            }
        }
    }
    //cout<<s1<<endl;
    return 0;
}
//4658179125601
//9999999999
//9999999993

#include<bits/stdc++.h>

#define ll long long int

using namespace std;

const ll COPIES = 1e10;
int cnt;

int main () {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    int n, i, flag = 0;
    string t;
    cin >> n >> t;
    string a = "", b = "", tmp = "";
    cnt = 0;
    for (i=0; i<n && flag < 2; i++) {
        tmp += t[i];
        if (t[i] == '0') {
            if (tmp == "110" && flag < 2) {
                flag = 1;
                cnt++;
                tmp = "";
            }
            else if (tmp.size() > 2) flag = 2;
            else {
                if (flag == 0) {
                    a = tmp;
                    flag = 1;
                    tmp = "";
                }
                else if (flag == 1) {
                    b = tmp;
                    flag = 2;
                }
            }
        }
    }
    if (i < n || tmp.size() > 2 || (tmp.size() && tmp[tmp.size()-1] == '0')) cout << "0\n";
    else {
        b = tmp;
        if (a.size() == 0 && b.size() == 0) cout << COPIES - cnt + 1 << endl;
        else if (a.size() == 0 && cnt == 0 && b == "1") cout << 2*COPIES << endl;
        else if (a.size() == 0 || b.size() == 0) cout << COPIES - cnt << endl;
        else cout << COPIES - cnt - 1 << endl;
    }

    return 0;
}