#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using P = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
using vll = vector<vl>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
const ll INF = 1LL << 60;
const double pi = acos(-1);
ll mod = 1000000007;

ll gcd(ll a, ll b){
    if(a%b == 0){
        return b;
    }else{
        return gcd(b,a%b);
    }
}

ll lcm(ll a, ll b){
    return a * b / gcd(a, b);
}

int main() {
    int n; cin >> n;
    string t; cin >> t;
    ll ans = 0;
    int zero = 0, one = 0, k = 0;
    for(auto i : t){
        if(i == '0') {
            zero++;
            one = 0;
        }
        if(i == '1') {
            one++;
            zero = 0;
        }
        if(k < n - 2){
            if(t[k] == '0' && t[k+1] == '1' && t[k+2] == '0') {
                cout << ans << endl;
                return 0;
            }else{
                k++;
            }
        }
        if(zero == 2 || one == 3){
            cout << ans << endl;
            return 0;
        }
    }
    if(n == 1 && t[0] == '1'){
        ans = 2 * (ll)1e10;
    }else if(n == 1 && t[0] == '0'){
        ans = (ll)1e10;
    }else if(n == 2){
        if(t[0] == '1' && t[1] == '1' || t[0] == '1' && t[1] == '0'){
            ans = (ll)1e10;
        }else{
            ans = (ll)1e10 - 1;
        }
    }else if(n%3 == 0){
        if(t[0] == '1' && t[1] == '1' && t[2] == '0'){
            ans = (ll)1e10 - n / 3 + 1;
        }else{
            ans = (ll)1e10 - n / 3;
        }
    }else{
        if(n%3==2 && t[0] == '0') ans = (ll)1e10 - n / 3 - 1;
        else ans = (ll)1e10 - n / 3;
    }
    cout << ans << endl;
    return 0;
}

#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define eps 1e-9
#define rep(i,l,r) for(int i=l;i<r;i++)
#define rrep(i,r,l) for(int i=r-1;i>=l;i--)
typedef long long ll;
const int maxn=2e5+5;
int n;
char t[maxn];
void solve()
{
	if(n==1){
		if(t[0]=='1') printf("20000000000\n");
		else printf("10000000000\n");
		return ;
	}
	ll ans=0;
	bool ok=true;
	int l=0,r=n-1,x=0;;
	while(l<n&&t[l]!='0') ++l;
	while(r>=0&&t[r]!='0') --r;
	if(l<n) ++l;
	++r;
	if(l>3||r<n-2) ok=false;
	if(ok){
		rep(i,l,r){
			if(t[i]=='0'){
				if(x==2) x=0,++ans;
				else {
					ok=false;
					break;
				}
			}
			else ++x;
		}
	}
	if(x) ok=false;
	if(r!=n&&r>=l) ++ans;
	printf("%lld\n",ok?10000000000-ans:0);
}
int main()
{
	scanf("%d %s",&n,t);
	solve();
	return 0;
}