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

#define ll long long
int main()
{
    string s;
    string tmp = "110";
    int n;
    cin >> n;
    cin >> s;

    ll ans = 0;
    for (int i = 0; i < 3; i++)
    {
        bool ok = 1;
        for (int j = 0; j < n; j++)
            if (s[j] != tmp[(i + j) % 3])
            {
                ok = 0;
                break;
            }
        if (ok)
            ans += (10000000000LL * 3 - i - n) / 3 + 1;
    }
    cout << ans << endl;
}
#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;
  }
    
}