#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mkp make_pair
#define vi vector<int>
#define pii pair<int,int>
#define FI(n) FastIO::read(n)
#define FO(n) FastIO::write(n)
#define ull unsigned long long
#define mst(a,b) memset(a,b,sizeof(a))
#define foR(i,k,j) for(int i=(k);i>=(j);i--)
#define For(i,k,j) for(int i=(k);i<=(j);i++)
#define Foe(i,u) for(int i=lst[u],v=e[i].v;i;i=e[i].nxt,v=e[i].v)
#define IOS ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define Fin(s) freopen(s,"r",stdin)
#define Fout(s) freopen(s,"w",stdout)
#define file(s) Fin(s".in"),Fout(s".out")
#define INF ((1<<30)-1)
#define int long long
const int P=998244353; //
using namespace std;
template<typename T>inline void ckmax(T &a,T b) {(a<b)&&(a=b);}
template<typename T>inline void ckmin(T &a,T b) {(a>b)&&(a=b);}
inline int mul(int a,int b) {return 1ull*a*b%P;}
inline int add(int a,int b) {return a+b>=P?a+b-P:a+b;}
inline int sub(int a,int b) {return a-b>=0?a-b:a-b+P;}
inline void mulmod(int &a,int b) {a=mul(a, b);}
inline void addmod(int &a,int b) {((a+=b)>=P)&&(a-=P);}
inline void submod(int &a,int b) {((a-=b)<0)&&(a+=P);}
inline int ksm(int a,int b) {int ans=1; for(;b;b>>=1) {if(b&1) ans=1ll*ans*a%P;a=1ll*a*a%P;}return ans;}
inline void fprint(const int &x,char c=' ') {fprintf(stderr,"%d%c",x,c);}
inline void fprint(const pii &x,char c='\n') {fprintf(stderr,"%d %d%c",x.first,x.second,c);}
inline void fprint(const int *f,const int &n,char c='\n') {for(int i=1;i<=n;i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline void fprint(const vector<int> &f,char c='\n') {for(int i=0;i<(int)f.size();i++) fprint(f[i]); fprintf(stderr,"%c",c);}
inline int inv(int a) {return ksm(a,P-2);}
namespace FastIO {
  const int SIZE=1<<16; char buf[SIZE],obuf[SIZE],str[64]; int bi=SIZE,bn=SIZE,opt;
  int read(char *s) {
    while (bn) {for (;bi<bn&&buf[bi]<=' ';bi++);if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}
    int sn=0;while (bn) {for (;bi<bn&&buf[bi]>' ';bi++) s[sn++]=buf[bi];if (bi<bn) break; bn=fread(buf,1,SIZE,stdin),bi=0;}s[sn]=0;return sn;
  }
  bool read(int& x) {if(x)x=0;int bf=0,n=read(str); if(!n) return 0; int i=0; if (str[i]=='-') bf=1,i=1; for(x=0;i<n;i++) x=x*10+str[i]-'0'; if(bf) x=-x; return 1;}
  void write(int x) {
    if(!x) obuf[opt++]='0'; else {if(x<0) obuf[opt++]='-',x=-x;int sn=0; while(x)str[sn++]=x%10+'0',x/=10;for (int i=sn-1;i>=0;i--) obuf[opt++]=str[i];}
    if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}
  }
  void write(char x) {obuf[opt++]=x;if (opt>=(SIZE>>1)){fwrite(obuf,1,opt,stdout); opt=0;}}
	void Fflush() {if (opt) fwrite(obuf,1,opt,stdout); opt=0;}
};
inline int read() {int x; FI(x); return x;}
const int MN=5e5+5;
int n,a[MN],b[MN],m; char s[MN];
signed main() {
	#ifndef ONLINE_JUDGE
		file("pro"); 
	#endif
	n=read();
	FI(s+1); For(i,1,n) a[i]=s[i]-'0';
	if(n==1) {
		cout<<((a[1]==1)?20000000000ll:10000000000ll)<<endl;
		return 0;
	}
	For(i,1,n) {
		if(a[i]==1&&a[i+1]==1&&a[i+2]==0) {
			b[++m]=2;	i=i+2;
		} else b[++m]=a[i];
	}
	int st=1,ed=0;
	For(i,1,n) {
		if(b[i]==2) {
			st=i;	break;
		}
	}
	foR(i,n,1) {
		if(b[i]==2) {
			ed=i; break;	
		}
	}
	For(i,st,ed) if(b[i]!=2) {
		return printf("0\n"),0;	
	} 
//	cerr<<"?";
	int ss=0;
	if(b[1]==1) {
		if(b[1+1]!=0) return printf("0\n"),0;
		ss=2;	
	} else if(b[1]==0) {
		if(n==2&&b[2]==1) ss=3;
		else {
			if(b[1+1]!=2) return printf("0\n"),0;	
			ss=3;	
		}
		
	} else ss=1;
	if(n>=3) {
		if(b[m]==1&&n>3) {
			if(b[m-1]==0) return printf("0\n"),0;	
		}
		if(b[m]==0) {
			if(b[m-1]!=2) return printf("0\n"),0;	
		}	
	}
	
	int epos=30000000000ll-n+1;
	cout<<(epos-ss)/3+1<<endl;
	return FastIO::Fflush(),0;
}


#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<vector>
#include<string.h>
#include<math.h>
#include<map>
#include<iomanip>
#include<queue>
#include<set>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;

//const ll mod = 1e9 + 7;
const ll mod = 998244353;
const int inf = 123456789;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(15);
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for(int i = 0; i < n - 2; i++){
		string t = s.substr(i , 3);
		if(t == "110"){
			cnt++;
		}
		if(t == "111"){
			cout << 0 << endl;
			return 0;
		}
		if(t == "010"){
			cout << 0 << endl;
			return 0;
		}
	}

	for(int i = 0; i < n - 1; i++){
		if(s.substr(i , 2) == "00"){
			cout << 0 << endl;
			return 0;
		}
	}

	if(s == "1"){
		cout << 20000000000 << endl;
		return 0;
	}
	if(s == "11" || s == "0" || s == "10" || s == "110"){
		cout << 10000000000 << endl;
		return 0;
	}
	if(s == "01" || s == "011" || s == "101" || s == "1011"){
		cout << 10000000000 - 1 << endl;
		return 0;
	}

	/*
	if(n >= 5 && n / 3 - 1 > cnt){
		cout << 0 << endl;
		return 0
	}
	*/

	if(s.substr(0 , 3) == "110" && s.substr(n - 3 , 3) == "110"){
		ll ans = 10000000000 - cnt + 1;
		cout << ans << endl;
		return 0;
	}

	if(s.substr(0 , 3) == "110" || s.substr(n - 3 , 3) == "110"){
		ll ans = 10000000000 - cnt;
		cout << ans << endl;
		return 0;
	}

	ll ans = 10000000000 - cnt - 1;
	cout << ans << endl;

	return 0;
}