#include <bits/stdc++.h>
using namespace std;
const int N = 500001;
const int oo = 1e9;
const int LOGN = 20;
const int MOD = 1000000007;
const double PI = acos(-1);
int n, f[41];
long long dp[41][41][41][2];
string t;
void fail() {
  int len = 0;
  for (int i = 1; i < t.size(); ++i) {
    while (len > 0 && t[i] != t[len]) len = f[len - 1];
    if (t[i] == t[len]) len++;
    f[i] = len;
  }
}
int match(int cur, char nx) {
  if (cur == t.size()) cur = f[cur - 1];
  while (cur > 0 && t[cur] != nx) cur = f[cur - 1];
  if (t[cur] == nx) cur++;
  return cur;
}
long long calc(long long idx, long long pre, long long suf, bool done) {
  if (pre == t.size()) done = true;
  if (idx == n) return (pre == suf) && done;
  long long &ret = dp[idx][pre][suf][done];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = '0'; i <= '1'; ++i)
    ret = ret + calc(idx + 1, match(pre, i), suf, done);
  return ret;
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n >> t;
  fail();
  long long ans = 0;
  for (int i = 0; i <= t.size(); ++i) {
    ans += calc(0, i, i, 0);
  }
  cout << ans << endl;
  return 0;
}
