#include <bits/stdc++.h>
using namespace std;
const int MAXN = 105;
char s[MAXN];
int n, m, nxt[MAXN], ch[MAXN][2];
long long ans, f[MAXN][MAXN][MAXN];
int main() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  m = strlen(s + 1);
  for (int i = 1; i <= m; i++) ch[i - 1][s[i] - '0'] = i;
  for (int i = 1; i <= m; i++)
    for (int c = 0; c < 2; c++)
      if (ch[i][c])
        nxt[ch[i][c]] = ch[nxt[i]][c];
      else
        ch[i][c] = ch[nxt[i]][c];
  long long ans = 1ll << n;
  for (int i = 0; i < m; i++) {
    memset(f, 0, sizeof f);
    f[0][0][i] = 1;
    for (int j = 1; j <= n; j++) {
      for (int k = 0; k <= m; k++)
        for (int l = 0; l <= m; l++)
          for (int c = 0; c < 2; c++) {
            int nk = ch[k][c], nl = ch[l][c];
            if (nk < m && nl < m) f[j][nk][nl] += f[j - 1][k][l];
          }
    }
    for (int j = 0; j < m; j++) ans -= f[n][i][j];
  }
  printf("%lld\n", ans);
}
