#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 42;
const long long mod = 1e9 + 7;
long long pw(long long a, long long b, long long md = mod) {
  long long res = 1;
  while (b) {
    if (b & 1) {
      res = (a * res) % md;
    }
    a = (a * a) % md;
    b >>= 1;
  }
  return (res);
}
vector<int> kmp(string s) {
  int n = s.size();
  vector<int> f(n);
  for (int i = 1; i < n; i++) {
    int j = f[i - 1];
    while (j and s[i] != s[j]) j = f[j - 1];
    j += (s[i] == s[j]), f[i] = j;
  }
  return (f);
}
int n, m;
string s;
long long ans = 0;
long long dp[maxn][maxn][maxn][2];
vector<int> f;
int find(int pos, char c) {
  if (pos == m) pos = f[pos - 1];
  while (s[pos] ^ c)
    if (!pos)
      return pos;
    else
      pos = f[pos - 1];
  return pos + 1;
}
long long solve(int rmn, int cur, int tar, int full) {
  if (cur == m) full |= 1;
  if (!rmn) return cur == tar && full;
  if (~dp[rmn][cur][tar][full]) return dp[rmn][cur][tar][full];
  dp[rmn][cur][tar][full] = solve(rmn - 1, find(cur, '0'), tar, full);
  dp[rmn][cur][tar][full] += solve(rmn - 1, find(cur, '1'), tar, full);
  return dp[rmn][cur][tar][full];
}
int32_t main() {
  cin.tie(0)->sync_with_stdio(0);
  cin >> n >> s;
  m = s.size();
  f = kmp(s);
  memset(dp, -1, sizeof dp);
  for (int i = 0; i <= m; i++) ans += solve(n, i, i, 0);
  cout << ans;
  return (0);
}
