#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
void dbg_out() { cerr << endl; }
template<typename Head, typename... Tail> void dbg_out(Head H, Tail... T) { cerr << ' ' << H; dbg_out(T...); }
#ifdef WA_DEBUG
#define dbg(...) cerr << "(" << #__VA_ARGS__ << "):", dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

using ll  = long long;
using vi  = vector<int>;
using ull = unsigned long long;
#define pb push_back
#define fi first
#define se second
#define rep(i,a,b) for(int i=int(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=int(a);i>=(int)(b);i--)
const int mod  = 1e9+7;
const int inf  = 0x3f3f3f3f;
const int maxn = 1e5+10;
int main() {
#ifndef WA_DEBUG
    ios::sync_with_stdio(false);cin.tie(nullptr);
#endif
    int n;
    cin>>n;
    string s;
    ll ans=1e10;
    cin>>s;
    if(n==1) {
        if(s[0]=='1') cout<<ans*2<<'\n';
        else cout<<ans<<'\n';
        return 0;
    }
    rep(i,0,2) {
        int now=i;
        bool f=true;
        for(char c:s) {
            char tmp;
            if(now==0) tmp='1';
            if(now==1) tmp='1';
            if(now==2) tmp='0';
            if(tmp!=c) {
                f=false;
                break;
            }
            now=(now+1)%3;
        }
        if(f) {
            int len=i+n;
            len=len/3+(!!(len%3));
            ans=ans-len+1;
            cout<<ans<<'\n';
            return 0;
        }
    }
    cout<<0<<'\n';
    return 0;
}

#include<iostream>
#include<cmath>
using namespace std;
#define ll long long
int main(){
	ll n,ans,N=10000000000;
	char s[200005];
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>s[i];
	}
	char last='2';
	ll num1=0,num0=0;
	bool flag=0;
	for(ll i=0;i<n;i++){
		if(s[i]=='0'){
			num0++;
			if(num0>1){
				flag=1;
				break;
			}
			if(last=='1'){
				if(num1<2&&i!=1){
					flag=1;
					break;
				}
				num1=0;
			}
		}
		else{
			num1++;
			if(num1>2){
				flag=1;
				break;
			}
			num0=0;
		}
		last=s[i];
		if(flag){
			break;
		}
	}
	if(flag){
		cout<<0;
		return 0;
	}
	if(n==2&&!(s[0]=='0'&&s[1]=='1')){
		cout<<N;
		return 0; 
	}
	else if(n==1){
		if(s[0]=='0'){
			cout<<N;
			return 0;
		}
		else{
			cout<<N*2;
			return 0;
		}
	}
	if(s[0]=='0'){
		n-=1;
	}
	else{
		if(s[1]=='0'){
			n-=2;
		}
		else{
			n-=3;
		}
	}
	ans=n/3;
	if(n%3){
		ans++;
	}
	cout<<N-ans;
}