/*	_____________________
	|Author : canhnam357|
	|___________________|
*/
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <string> vs;
typedef vector <vector <int>> vvi;
typedef vector <vll> vvll;
typedef map<int, int> mi;
typedef map<string, int> ms;
typedef map<char, int> mc;
typedef map <int, bool> mb;
typedef map<ll, ll> mll;
typedef unordered_map<int, int> umi;
typedef unordered_map<string, int> ums;
typedef unordered_map<char, int> umc;
typedef unordered_map <int, bool> umb;
typedef unordered_map<ll, ll> umll;
typedef vector <ld> vld;
typedef vector <bool> vb;
typedef pair <int, int> pii;
typedef pair<ll, ll> pll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
int CASE = 1;
const int mxn = 4e3 + 1;
const ll INF = 1e10;
#define FOR(i,N) for(ll i = 0 ; i < N;i++)
#define eFOR(i,a,b) for(ll i = a; i <=b;i++)
#define dFOR(i,N) for(ll i = N - 1; i>=0;i--)
#define edFOR(i,b,a) for(ll i = b ; i >=a;i--)
#define all(x) x.begin(),x.end()
#define SORT(x) sort(all(x))
#define RSORT(x) sort(x.rbegin(),x.rend())
#define UNQ(x)  unique(all(x))
#define mine(x) min_element(all(x))
#define maxe(x) max_element(all(x))
#define lb(v, x) lower_bound(all(v) , x)
#define ub(v , x) upper_bound(all(v) , x)
#define pb push_back
#define PI 3.141592653589793
#define FIX cout << fixed << setprecision(15)
#define g(i , a) get<i>(a)
const ll mod = 2e5;
bool prime(ll n)
{
	if (n <= 1)
		return false;
	eFOR(i, 2, sqrt(n))
		if (!(n % i))
			return false;
	return true;
}
ll __gcd(ll a, ll b)
{
	return !b ? a : __gcd(b, a % b);
}
void solve()
{
	int n;
	string t;
	cin >> n >> t;
	string s = "";
	if (t.length() == 1)
	{
		if (t == "1")
			cout << 2LL * INF;
		else
			cout << INF;
		return;
	}
	while (s.length() < mod)
		s += "110";
	if (s.find(t) == -1)
	{
		cout << 0;
		return;
	}
	bool ok = true;
	int cnt = 0;
	for (char c : t)
	{
		if (ok)
		{
			ok = false;
			cnt++;
		}
		if (c == '0')
			ok = true;
	}
	cout << INF - cnt + 1;
}
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T = 1;
	while (T--)
	{
		solve();
	}
	return 0;
}
#include<bits/stdc++.h>
using namespace std;
#define me(a,x) memset(a,x,sizeof(a))
#define sc scanf
#define pr printf
#define IN freopen("in",stdin);
#define OUT freopen("out","w",stdout);
typedef long long ll;
typedef unsigned long long ull;
const int N=1e7+6;
const int mod=1e9+7;
int O(){putchar('\n');return 0;}template<typename T,typename... Ty>
int O(const T& a,const Ty&... b){cout<<a<<' ';return O(b...);}
void I(){}template<typename T,typename... Ty>void I(T& a,Ty&... b){cin>>a;I(b...);}
template<typename T>void db(T *bg,T *ed){while(bg!=ed)cout<<*bg++<<' ';pr("\n");}
inline ll mul_64(ll x,ll y,ll c){return (x*y-(ll)((long double)x/c*y)*c+c)%c;}
inline ll ksm(ll a,ll b,ll c){ll ans=1;for(;b;b>>=1,a=a*a%c)if(b&1)ans=ans*a%c;return ans;}
int n;
string s;
//110
//101
//011
string p[]={"110","101","011"};
ll m=1e10;
int check(string x){
    for(int i=0;i<3;i++){
        if(p[i]==x){
            return i;
        }
    }
    return -1;
}
bool istrue(int pos){
    int n=s.size();
    for(int i=0;i<n;i+=3){
        if(n-i<3){
            if(p[pos].substr(0,n-i)!=s.substr(i,n-i))return false;
            return true;
        }
        if(p[pos]!=s.substr(i,3))return false;
    }
    return true;
}
int main(){
    I(n,s);
    if(n==1){
        if(s[0]=='0')return O(m);
        else return O(m*2);
    }
    if(n==2){
        if(s=="00")return O(0);
        if(s=="11"||s=="10")return O(m);
        return O(m-1);
    }
    int pos=check(s.substr(0,3));
    if(pos==-1)return O(0);
    bool f=istrue(pos);
    if(!f)return O(0);
    ll ans=m*3-n-pos;
    ll k=ans/3;
    while(3LL*k+n+pos<=m*3)k++;
    O(k);
}
