#include "bits/stdc++.h"
using namespace std;
#define dbg(var) cout<<#var<<"="<<var<<" "
#define nl cout<<"\n"
#define fr(i,n) for(int i=0;i<n;i++)
#define rep(i,a,n) for(int i=a;i<=n;i++)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define fa(v) for(auto &i:v)
#define all(v) v.begin(),v.end()
#define sz(v) (int)(v.size())
#define int long long
#define kill(x) {cout << x << "\n" ; return;}
template<typename T>
vector<int> get_pi(const T &a) {
int n = a.size();
vector<int> pi(n);
int j = 0;
for (int i = 1; i < n; i++) {
while (j > 0 && a[i] != a[j]) j = pi[j - 1];
j += ((a[i] == a[j]) ? 1 : 0);
pi[i] = j;
}
return pi;
}
int get_occurences(string t, string pat){
t = pat + "#" + t;
vi tot = get_pi(t);
int ans = 0;
for(int x: tot)
ans += (x == (int)pat.size());
return ans;
}
void solve(){
// 10 ^ 10 = 10 ^ 6 * 10 ^ 4
string T;
fr(_,(int)1e6) T += "110";
int n; cin >> n;
string pat; cin >> pat;
int no1 = get_occurences(T,pat);
if(no1 == 0) kill(0);
string T2= T + T;
int no2 = get_occurences(T2,pat);
string T3 = T + T +T ;
int no3 = get_occurences(T3,pat);
// cout << no1 << " " << no2 << " " << no2 - no1 <<"\n";
// dbg(no3);nl;
int d = no2 - no1;
cout << no1 + (d) * (10000 - 1);
}
int32_t main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
// int tst; cin >> tst; while(tst--)
{
solve();
}
}