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