//Many 110 

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define rrep(i,x,y) for(ll i=x-1;i>=y;i--)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define nnn "\n"
#define spa " "
using P = pair<ll,ll>;
using graph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18
//cout<<fixed<<setprecision(15)<<x<<nnn;

signed main (){
    int n;string t;cin>>n>>t;
    int ans=0;
    string s;
    rep(i,0,n/3+2){
        s.push_back('0');
        s.push_back('1');
        s.push_back('1');
    }
    bool flag=false;
    rep(i,0,3)rep(j,0,n){
        if(t[j]!=s[i+j])break;
        if(j==n-1)flag=true;
    }
    if(flag){
        if(n==1){
            if(t[0]=='1')ans=2*1e10;
            else ans=1e10;
        }else if(n==2){
            if(t[0]=='0')ans=1e10-1;
            else ans=1e10;
        }else{
            if(t[0]=='0')ans=(3e10-2-n)/3+1;
            else if(t[1]=='0')ans=(3e10-1-n)/3+1;
            else ans=(3e10-n)/3+1;
        }
    }
    cout<<ans<<nnn;
    return 0;
}
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;


ll N, ans;
string Tstr;

ll check_valid(ll offset, const char* T) {
	ll i;
	ll m;
	const char* valid = "110";
	m = 0;
	for (i = offset; i < N; i++) {
		if (T[i] != valid[m]) {
			return -1;
		}
		m++;
		if (m == 3) m = 0;
	}

	//cout << "passed" << endl;

	ll n = (N - offset) / 3;
	ll left = (N - offset) % 3;
	if (left > 0) n++;

	if (offset == 0) {
		return n - 1;
	}
	else {
		return n;
	}
}


int main() {
	
	N = 1E10;
	cin >> N;
	cin >> Tstr;

	if (N == 1) {
		if (Tstr.at(0) == '1') {
			ans = 2 * 1E10;
		}
		else {
			ans = 1E10;
		}
		cout << ans << endl;
		return 0;
	}

	if (N == 2) {
		auto check = Tstr.substr(0, 2);
		if (check == "11" || check == "10") {
			ans = 1E10;
		}
		else if (check=="01"){
			ans = 1E10-1;
		}
		else {
			ans = 0;
		}
		cout << ans << endl;
		return 0;
	}



	string head = Tstr.substr(0, 3);
	ll offset = 0;

	if (head == "110") {
		if (N == 3) {
			ans = 1E10;
			cout << ans << endl;
			return 0;
		}
		offset = 0;
	}
	else if (head == "101"){
		if (N == 3) {
			ans = 1E10-1;
			cout << ans << endl;
			return 0;
		}
		offset = 2;

	}
	else if (head == "011") {
		if (N == 3) {
			ans = 1E10 - 1;
			cout << ans << endl;
			return 0;
		}
		offset = 1;
	}
	else {
		ans = 0;
		cout << ans << endl;
		return 0;
	}

	// cout << "offset=" << offset << " T=" << Tstr << endl;
	ll ret= check_valid(offset, Tstr.c_str());

	if (ret == -1) {
		ans = 0;
	}
	else {
		ans = 1E10 - ret;
	}
	cout << ans << endl;
	return 0;
}

