#include <bits/stdc++.h>
using namespace std;
const int N = 45;
int ch[N][2], fa[N];
long long f[N][N], g[N][N], ans;
int n, m;
char s[N];
void build_mat() {
  fa[1] = 0;
  for (int i = (int)(1); i <= (int)(m); i++) {
    fa[i] = ch[fa[i - 1]][s[i]];
    ch[i - 1][s[i] ^ 1] = ch[fa[i - 1]][s[i] ^ 1];
    ch[i - 1][s[i]] = i;
  }
  ch[m][0] = ch[fa[m]][0];
  ch[m][1] = ch[fa[m]][1];
}
int main() {
  scanf("%d%s", &n, s + 1);
  m = strlen(s + 1);
  for (int i = (int)(1); i <= (int)(m); i++) s[i] -= '0';
  build_mat();
  f[0][m] = 1;
  g[0][m] = 1;
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(m); j++) {
      f[i][ch[j][0]] += f[i - 1][j];
      f[i][ch[j][1]] += f[i - 1][j];
    }
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(m - 1); j++) {
      g[i][j] += g[i - 1][ch[j][0]];
      g[i][j] += g[i - 1][ch[j][1]];
    }
  for (int i = (int)(1); i <= (int)(n); i++)
    for (int j = (int)(0); j <= (int)(m); j++) ans += f[i][j] * g[n - i][j];
  printf("%lld\n", ans);
}
