# include<bits/stdc++.h>
using namespace std;
# define l long long 
# define db double 
# define rep(i,a,b) for(l i=a;i<b;i++)
# define vi vector<l>
# define vvi vector<vi>
# define vsi vector<set<l> >
# define pb push_back
# define mp make_pair
# define ss second
# define ff first
# define pii pair<l,l>
# define trvi(v,it) for(vi::iterator it=v.begin();it!=v.end();++it)
# define read(a) freopen(a,"r",stdin)
# define write(a) freopen(a,"w",stdout)
# define io ios::sync_with_stdio(false)

#define ai(n) array<l,n>

const l MOD=1e9+7;
const l N=2 * 1e5 + 10;
const l INF=1e18;

ai(N) Pi; // Prefix function Pi
string P, T(200000,' '); // P is pattern, T is string
l n,m; // n is size of string, m is size of pattern

l startIdx=-1;

// This populates Pi
// Pi [i] gives length of longest suffix of Pi (1 indexed) that is a proper prefix of Pi.
void computePrefixFunction() {
	l k=0;
	Pi[1]=0;
	rep(q,1,m) {
		while(k>0 && P[k]!=P[q]) {
			k = Pi[k];
		}
		if(P[k]==P[q]) {
			k = k + 1;
		}
		Pi[q+1]=k;
	}
}


// If q==m, match found. Add code there to handle scenario when pattern is found
void KMPMatcher() {
	computePrefixFunction();
	n=T.length();
	l q=0;
	rep(i,0,n) {
		while(q>0 && P[q]!=T[i]) {
			q = Pi[q];
		}

		if(P[q]==T[i]) {
			q = q + 1;
		}
		if(q==m) {
			startIdx=i-m+1;
			q=Pi[q];
			return;
		}

	}
}


void solve() {
	m=0;
	cin>>m;
	n=T.length();
	rep(i,0,n) {
		if(i%3==2) {
			T[i]='0';
		} else {
			T[i]='1';
		}
	}
	cin>>P;
	
	n=T.length();
	KMPMatcher();
	if(m==1 && P[0]=='1') {
		l ans = 2 * 1e10;
		cout<<ans<<"\n";
		return;
	}
	if(startIdx==-1) {
		cout<<"0\n";
	} else {
		l numStringsReqd= (m-1+startIdx)/3;
		l ans= 1e10 - numStringsReqd;
		cout<<ans<<"\n";
	}
	return;
}


int main(){
	io;
	int t;
	// cin >> t;
	rep(i,0,1) {
		solve();
	}

	return 0;
}
#include <bits/stdc++.h>
using namespace std;

int main(){
  long long n,ju=10000000000;string t;
  cin>>n>>t;
  if(n==1&&t[0]=='1'){
    cout<<2*ju<<endl;return 0;
  }
  if(n==1&&t[0]=='0'){
    cout<<ju<<endl;return 0;
  }
  if(n==2){
    if((t[0]=='1'&&t[1]=='1')||(t[0]=='1'&&t[1]=='0')){
      cout<<ju<<endl;return 0;
    }
    else if(t[0]=='0'&&t[1]=='1'){
      cout<<ju-1<<endl;return 0;
    }
  }
  int c,k=0;
  if(t[0]=='1'&&t[1]=='1')c=0;
  else if(t[0]=='1'&&t[1]=='0')c=1;
  else if(t[0]=='0'&&t[1]=='1')c=2;
  else{
    cout<<0<<endl;
    return 0;
  }
  for(int i=0;i<n;i++){
    if((c%3==0&&t[i]=='1')||(c%3==1&&t[i]=='1')){
      c++;
    }
    else if(c%3==2&&t[i]=='0'){
      c++;k++;
    }
    else{
      cout<<0<<endl; return 0;
    }
  }
  if(t[n-1]=='1')cout<<ju-k<<endl;
  else cout<<ju-k+1<<endl;
}