///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>
using namespace std;
#define     FAST        ios_base::sync_with_stdio(false);cin.tie(NULL)
#define     int 	    long long
#define 	pb 	        push_back
#define     pp          pop_back
#define 	mp 	        make_pair
#define 	pi 	        2*acos(0.0)
#define     scan(i)     scanf("%lld",&i)
#define     scann(i,j)  scanf("%lld%lld",&i,&j)
#define     print(i)    printf("%lld\n",i)
#define     printt(i,j) printf("%lld %lld\n",i,j)
#define     loop(i,n) 	for(int i = 0 ; i <n ; i++)
#define     loopp(i,n) 	for(int i = 1 ; i <n ; i++)
#define     rep(i,n)    for(int i=n-1;i>=0;i--)
#define     rev(v)      reverse(v.begin(),v.end())
#define     reset(a,b)  memset(a,b,sizeof(a))
#define 	vect 	    vector<int>
#define 	vec_it 	    vector<int>::reverse_iterator vi
#define     sorta(v)    sort(v.begin(),v.end())
#define     sortd(v)    sort(v.begin(),v.end(),greater<>())
#define     sorted(v)   is_sorted(v.begin(),v.end())
#define 	mapp 	    map<int,int>
#define     rmap        map<int,int,greater<>>m
#define 	pairr 	    pair<int,int>
#define 	sett	    set<int>
#define     rset        set<int,greater<>>s
#define 	set_it 	    set<int>::reverse_iterator si
#define     map_it      map<int,int> :: reverse_iterator mi
#define     digit(n)    floor(log10(n)+1)
#define 	yes 	    cout<<"YES"<<endl
#define 	no 	        cout<<"NO"<<endl
#define 	ff 	        first
#define 	ss 	        second
#define     mx          INT_MAX
#define     lmx         LLONG_MAX
#define     mn          INT_MIN
#define     lmn         LLONG_MIN
#define     inf         0x3f3f3f3f
#define     inff        10e18
#define     GCD         __gcd(a,b)
#define     LCM         (a/GCD)*b
template <typename T> T gcd(T a,T b){return (b==0)?a:gcd(b,a%b);}
template <typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
int modulo (int a, int b) { return a >= 0 ? a % b : ( b - abs ( a%b ) ) % b; }

void solve()
{
   // freopen ("(input).txt" , "r",  stdin) ;
    string st,stt,str;
    int low=0,high=0;
    int l,r; char ch;
    int n,k,t,x,y,z,d=0,cnt=0,temp=0,sum=0,f=0,flag=0;
    cin>>n>>st ; vect v ,a ; sett s ; mapp m,mm ; pairr p ; stt="110";
    for(int i=0;i<100000;i++)
    {
        str+=stt;
    }
    sum=3*10000000000;
    if(n==1&&st[0]=='1')
        cout<<2*10000000000<<endl;
    else if(n==1&&st[0]=='1')
        cout<<10000000000<<endl;
    else if(n==2&&st[0]=='1'&&st[1]=='1'||n==2&&st[0]=='1'&&st[1]=='0')
        cout<<10000000000<<endl;
    else if(n==2&&st[0]=='0'&&st[1]=='1')
        cout<<10000000000-1<<endl;
    else if(str.substr(0,n)==st)
    {
        if(st[n-2]=='0'&&st[n-1]=='1')
            sum-=2;
        else if(st[n-2]=='1'&&st[n-1]=='1')
            sum--;
        sum-=(n-3);
        cout<<sum/3<<endl;
    }
    else if(str.substr(1,n)==st)
    {
        sum-=1;
        if(st[n-2]=='0'&&st[n-1]=='1')
            sum-=2;
        else if(st[n-2]=='1'&&st[n-1]=='1')
            sum--;
        sum-=(n-3);
        cout<<sum/3<<endl;
    }
    else if(str.substr(2,n)==st)
    {
        sum-=2;
        if(st[n-2]=='0'&&st[n-1]=='1')
            sum-=2;
        else if(st[n-2]=='1'&&st[n-1]=='1')
            sum--;
        sum-=(n-3);
        cout<<sum/3<<endl;
    }
    else
        cout<<0<<endl;

}

main()
{
    int t;
  //  cin>>t;
  //  while(t--)
        solve();
}

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>; 
using pll = pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
constexpr long long INF = 1e9+100;
constexpr long long LINF = 1e18+100;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define rept(i, j, n) for(int i=(j); i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll V = 1e10;

int main(){
    int n; string t; cin >> n >> t;
    if(t=="1")cout << V*2 << ln;
    else{
        if(t[0]=='0')t = "11" + t;
        else if(t.size()>=2 and t.substr(0, 2)=="10")t = "1" + t;

        if(t.size()%3==1){
            if(t.back()=='0'){
                cout << 0 << ln;
                return 0;
            }else t += "10";
        }else if(t.size()%3==2){
            if(t.substr(t.size()-2)=="11")t += "0";
            else{
                cout << 0 << ln;
                return 0;
            }
        }

        rep(i, t.size()){
            if(i%3==2 and t[i]!='0' or i%3!=2 and t[i]!='1'){
                cout << 0 << ln;
                return 0;
            }
        }
        ll res = V - t.size()/3 + 1;
        cout << res << ln;
    }
}