#include<bits/stdc++.h>
using namespace std;
#define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> p2;
#define sz(a) ll(a.size()) 
char t[300005];
void solve(){
	ll n;
	string s;
	cin>>n>>s;
	if(s=="1"){
		cout<<ll(2*pow(10,10));
		return;
	}
	ll j=0;
	while(j<300005){
		if(j%3==2)
			t[j]='0';
		else
			t[j]='1';
		j++;
	}
	for(ll i=0;i<3;i++){
		ll f=0;
		for(ll j=i;j<i+n;j++)
			if(s[j-i]!=t[j]){
				f=1;
				break;
			}
		if(!f){
			cout<<ll(pow(10,10))-(n+i-1)/3;
			return;
		}
	}
	cout<<0;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w", stdout);
    #endif
    clock_t z=clock();
    ll qc=1;
    //cin>>qc;
    for(ll i=1;i<=qc;i++)
        solve();
    debug("Total Time:%.4Lf\n",(ld)(clock()-z)/CLOCKS_PER_SEC);
}
// #pragma GCC optimize(2)
// #include <random>
// #include <windows.h>
// #include <ctime>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <bitset>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
#define IO                       \
    ios::sync_with_stdio(false); \
    // cout.tie(0);
#define lson(x) (x << 1)
#define rson(x) (x << 1 | 1)
using namespace std;
// int dis[8][2] = {0, 1, 1, 0, 0, -1, -1, 0, 1, -1, 1, 1, -1, 1, -1, -1};
typedef unsigned long long ULL;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 2e5 + 10;
const int maxm = 1e7 + 10;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const LL mod = 998244353;
const double eps = 1e-8;
const double pi = acos(-1);
int dis[4][2] = {1, 0, 0, -1, 0, 1, -1, 0};
// int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char s[maxn];
int main()
{
#ifdef WXY
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
#endif
    // IO;
    int n;
    // cin >> n;
    scanf("%d", &n);
    scanf("%s", s + 1);
    LL temp = LL(pow(10, 10));
    if (n == 1)
    {
        if (s[1] == '1')
            cout << temp * 2;
        else
            cout << temp;
        return 0;
    }
    else if (n == 2)
    {
        if (s[1] == '0' && s[2] == '0')
            cout << 0;
        else if (s[1] == '1' && s[2] == '1')
            cout << temp;
        else if (s[1] == '0' && s[2] == '1')
            cout << temp - 1;
        else
            cout << temp;
        return 0;
    }
    int p = -1;
    for (int i = 1; i <= n; i++)
    {
        if (s[i] == '0')
        {
            p = i;
            break;
        }
    }
    if (p > 3 || (p == -1))
    {
        cout << 0;
        return 0;
    }
    for (int i = p; i <= n; i++)
    {
        if (s[i] == '0')
        {
            if (i == n)
                break;
            else if (i + 3 <= n && s[i + 1] == '1' && s[i + 2] == '1' && s[i + 3] == '0')
                continue;
            else if (i + 2 == n && s[i + 1] == '1' && s[i + 2] == '1')
                continue;
            else if ((i + 1 == n && s[i + 1] == '1'))
                break;
            else
            {
                cout << 0;
                return 0;
            }
        }
    }
    if (s[n - 1] == '0' && s[n] == '1')
        n += 2;
    else if (s[n - 1] == '1' && s[n] == '1')
        n += 1;

    if (p == 2)
        n += 1;
    if (p == 1)
        n += 2;

    LL cnt = n / 3;
    cout << LL(pow(10, 10)) - cnt + 1;
    return 0;
}