#include <bits/stdc++.h>
//#define DEBUG
#define REP(i, nn ) for(int i = 0 ; i < (int) nn; i++)
#define deb(x) std::cout << #x << " " << x << endl;
#define debl(x) std::cout << #x << " " << x << " ";
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
template<typename... T>
void read(T& ... a){
    ((cin >> a),...);
}
template<typename... T>
void write(T... a){
    ((cout << a << "\n"),...);
}

template<typename... T>
void write_space(T... a){
    ((cout << a << " "),...);
}
const string s = "110";
const int sz = s.size();
constexpr ll L = 3e10; 

void solve(){        
    ll n ;
    cin >>n;
    string t;
    cin >> t;
    if( n == 1){
        if(t[0] == '1'){
            cout << 2 * L / 3 << endl;
        }else{
            cout << L / 3 << endl;
        }
        return;
    }
    bool match;
    int start = -1;
    for(start = 0 ; start < sz; start++){
        match = true;
        for(int i = 0 ; i < (int) t.size(); i++){
            int j = (i + start) % sz; 
            if( t[i] != s[j]){
                match = false;
                break;
            }
        }
        if(match) break;
    }
    if(match == false){
        cout << 0 << endl;
    }else{          
        assert(start >= 0);
        ll end = L - n;
        // debl(start) deb(end)
        ll ans = end / 3;
        if(end % 3 >= start){
            ans++;
        }
        cout << ans << endl;
    }
}

int main()
{
    //making data IO Fast
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(NULL);
    /****************************/
    solve();
    return 0;
}


#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>
#include <functional>
#include <iomanip>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);
constexpr int INF = (1 << 30);
//constexpr ll INF = (1LL << 60);

int main(void) {
	ll n;
	string t;
	cin >> n >> t;
	
	ll ans = 0LL;
	
	if( n == 1 ) {
		if( t == "1" ) {
			ans = 2LL * 1e10;
		} else {
			ans = 1e10;
		}
	} else if( n == 2 && t == "11" ) {
		ans = 1e10;
	} else {
		bool f = true;
		int num_zero = 0;
		
		for(int i = 0; i < n; ++i) {
			if( i < n - 1 ) {
				string tmp = t.substr(i, 2);
				
				if( tmp == "00" ) {
					f = false;
					break;
				}
			}

			if( t[i] == '0' ) num_zero++;			
		}
		
		for(int i = 0; i < n - 2; ++i) {
			string tmp = t.substr(i, 3);
			
			if( tmp == "111" || tmp == "010" ) {
				f = false;
				break;
			}	
		}
		
		if( f ) {
			if( t.back() == '0' ) {
				ans = 1e10 - num_zero + 1;
			} else {
				ans = 1e10 - num_zero;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
