#include <bits/stdc++.h>
using namespace std;
inline int read();
inline void write(int x);
const int M = 45, MOD = 1000000007;
char str[M];
int c[M][2], nxt[M], n, m;
long long ans, f[M][M][M];
int main(void) {
  scanf("%d%s", &n, str + 1);
  m = strlen(str + 1);
  for (int i = 1; i <= m; i++) c[i - 1][str[i] - '0'] = i;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j <= 1; j++)
      (c[i][j] ? nxt[c[i][j]] : c[i][j]) = c[nxt[i]][j];
  ans = 1ll << n;
  for (int i = 0; i < m; i++) {
    memset(f, 0, sizeof(f));
    f[0][0][i] = 1;
    for (int j = 0; j < n; j++) {
      for (int k = 0; k < m; k++) {
        for (int l = 0; l < m; 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; j++) ans -= f[n][i][j];
  }
  cout << ans << endl;
  return 0;
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) write(x / 10);
  putchar(x % 10 + '0');
}
