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

const int64_t MAX = 10000000000;

int64_t is_valid(string &S, string &T){
  int64_t ret = -1;
  for(int i=0; i<S.size() - T.size()+1; i++){
    bool flag = true;
    for(int j=0; j<T.size(); j++){
      if(S[i+j] != T[j]){
        flag = false;
      }
    }
    if(flag){
      ret = i;
      break;
    }
  }
  return ret;
}
      

int main(){
  int N;
  cin >> N;
  string T;
  cin >> T;
  if(T == "1"){
    cout << MAX*2 << endl;
    return 0;
  }
  if(T == "11" || T == "0"){
    cout << MAX << endl;
    return 0;
  }
  
  string A = "110";
  string S = "";
  for(int i=0; i<(N+4)/3; i++){
    S += A;
  }
  //cout << S << endl;
  
  int64_t x = is_valid(S,T);
  if(x == -1){
    cout << 0 << endl;
  }
  else{
    int64_t ok = 0;
    int64_t ng = MAX+10;
    while(ng - ok > 1){
      int64_t mid = (ok+ng)/2;
      if((mid-1)*3 + N <= MAX*3 - x){
        ok = mid;
      }
      else{
        ng = mid;
      }
    }
    cout << ok << endl;
  }
    
}
#include "bits/stdc++.h"
#pragma GCC optimize "trapv"

#define int long long
#define For(i,a,b) for(int  i=a;i<b;i++)

#define pb push_back
#define endl "\n"

#define F first
#define S second

#define drink_boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(v) v.begin(),v.end()

#define TEST_CASE int  t;cin>>t;while(t--)
#define debug(...) cout<<#__VA_ARGS__<<" = "; print(__VA_ARGS__);

using namespace std;
const int MOD = 1e9 + 7;

void print()  {    cout<<endl;  }
void printArray()  {    return;  }
void read() { return; }

template<typename T , typename... Args>  void print(T a , Args... arg)    {    cout << a << " " ;    print(arg...);    }

template<typename T , typename... Args> void read(T &a , Args&... arg) {   cin >> a;   read(arg...);   }

template<typename T,typename... Args> void read(vector<T>&v , Args&... arg) {  for(auto &i : v)  cin>>i;  read(arg...);  }

template<typename T,typename... Args> void printArray(vector<T>&v, Args&... arg) {   for(auto i : v)     cout<<i<<" ";   cout<<endl;  printArray(arg...);    }

int power(int a,int b) { int  res=1; while(b) { if(b&1LL) res=res*a; b>>=1LL; a=a*a; } return res; }
    
int modPower(int a,int b) { int res=1; while(b) { if(b&1L) res=(res%MOD*a%MOD)%MOD; b>>=1; a=(a%MOD*a%MOD)%MOD; } return res; }

int gcdExtended(int a,int b,int *x,int *y){ if(a==0) { *x=0,*y=1; return b; } int x1,y1; int gcd=gcdExtended(b%a,a,&x1,&y1); *x=y1-(b/a)*x1; *y = x1; return gcd; }

int modInverse(int b,int m) {int x,y; int g=gcdExtended(b,m,&x,&y); if (g != 1) return -1; return (x%m + m) % m; }

int modDivide(int a,int b,int m=MOD) { a=a%m; int inv=modInverse(b,m); if(inv==-1) return -1; else return (inv*a)%m; }

void runCase_()
{
   int n,a,b;
   read(n,a,b);
   int ans = n - a + b;
   print(ans);
}

signed main()
{
    drink_boost;
    // TEST_CASE
    runCase_();
    return 0;
}

/** TEST CASES HERE **/
/*

*/

