//This Code was made by Chinese_zjc_.
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <bitset>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <map>
#include <set>
#include <time.h>
// #include<windows.h>
#define int long long
#define double long double
const double PI = acos(-1);
const double eps = 0.0000000001;
const int INF = 0x3fffffffffffffff;
using namespace std;
int n;
string s;
signed main()
{
    ios::sync_with_stdio(false);
    cin >> n >> s;
    if (n < 3)
    {
        if (s == "1")
        {
            cout << 20000000000 << endl;
        }
        if (s == "0")
        {
            cout << 10000000000 << endl;
        }
        if (s == "11")
        {
            cout << 10000000000 << endl;
        }
        if (s == "01")
        {
            cout << 9999999999 << endl;
        }
        if (s == "10")
        {
            cout << 10000000000 << endl;
        }
        if (s == "00")
        {
            cout << 0 << endl;
        }
        return 0;
    }
    if (s[0] == '0')
    {
        s.insert(s.begin(), '1');
    }
    if (s[1] == '0')
    {
        s.insert(s.begin(), '1');
    }
    if (s[s.length() - 2] == '0')
    {
        s.push_back('1');
    }
    if (s[s.length() - 3] == '0')
    {
        s.push_back('0');
    }
    for (int i = 0; i < s.length(); ++i)
    {
        if (s[i] == '0' + (i % 3 == 2))
        {
            cout << 0 << endl;
            return 0;
        }
    }
    cout << 10000000001 - s.length() / 3 << endl;
    return 0;
}
/*#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n >> k;
  string s;cin>>s;
  vi a(n),b(n);
  REP(i,n) cin>>a[i];
  cout<<ans<<endl;
  return 0;
}
*/
#include "bits/stdc++.h"
using namespace std;
#define REP(i, n) for(ll i = 0;i < n;i++)
#define ll long long
#define MOD 1000000007LL
//#define MOD 998244353LL
#define doublecout(a) cout<<setprecision(16)<<a<<endl;
using vi = vector<ll>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vvvi = vector<vvi>; // intの2次元の型に vvi という別名をつける
const ll llMAX=9223372036854775807LL; 
const ll llMIN=-9223372036854775808LL;

void myprint1D(vi &data)
{
  REP(i,data.size())
    cout<<data[i]<<" ";
  cout<<endl;
}

//配列を[y][x]で表示
void myprint2D_T(vvi &data)
{
  REP(i,data.size())
    myprint1D(data[i]);
}

//配列を[x][y]で表示
void myprint2D(vvi &data)
{
  ll l1=data.size();
  ll l2=data[0].size();
  REP(j,l2){
    REP(i,l1)
      cout<<data[i][j]<<" ";
    cout<<endl;
  }
}

//print(a,b...)って使い方
void print1(ll a){cout<<a<<endl;}
void print2(ll a,ll b){cout<<a<<" "<<b<<endl;}
void print3(ll a,ll b,ll c){cout<<a<<" "<<b<<" "<<c<<endl;}
void print4(ll a,ll b,ll c,ll d){cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;}
void print5(ll a,ll b,ll c,ll d,ll e){cout<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl;}


ll n,k,x,y;

int main(){
  ll ans=0;
  cin >> n;
  string s,t;cin>>s;
  if (s=="0"){
    cout<<10000000000LL<<endl;
    return 0;
  }
  if (s=="1"){
    cout<<20000000000LL<<endl;
    return 0;
  }
  if (s=="11"){
    cout<<10000000000LL<<endl;
    return 0;
  }
  
  if (s=="00"){
    cout<<0<<endl;
    return 0;
  }
  
  if (s=="10"){
    cout<<10000000000LL<<endl;
    return 0;
  }
  
  if (s=="01"){
    cout<<(10000000000LL-1LL)<<endl;
    return 0;
  }

  t="110";
  string tt="";
  for(ll i=0;i<n/3+3;i++){
    tt+=t;
  }

  ll nn=(n/3+1)*3;
  ll flag=-1;
  if (s==tt.substr(2,n))flag=2;
  if (s==tt.substr(1,n))flag=1;
  if (s==tt.substr(0,n))flag=0;
  if (flag==-1){
    cout<<0<<endl;
    return 0;
  }

  nn=n+flag;
  cout<<((30000000000LL-nn+3)/3)<<endl;
  return 0;
}
