#include <bits/stdc++.h>
template <typename Y>
inline bool updmin(Y &a, Y b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename Y>
inline bool updmax(Y &a, Y b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename Y>
inline Y abs(Y a) {
  if (a < 0) a = -a;
  return a;
}
template <typename Y>
inline Y sqr(Y a) {
  return a * a;
}
int read() {
  int w = 1, q = 0, ch = ' ';
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') w = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar()) q = q * 10 + ch - 48;
  return q * w;
}
inline void FileIO() {
  freopen(
      ""
      ".in",
      "r", stdin);
  freopen(
      ""
      ".out",
      "w", stdout);
}
int n, m;
char s0[100];
int s[50], nxt[50][2];
long long f[50][50][50][50];
inline bool same(int l1, int r1, int l2, int r2) {
  for (int i = l1, j = l2; i <= r1; i++, j++) {
    if (s[i] != s[j]) return 0;
  }
  return 1;
}
int main() {
  n = read();
  scanf("%s", s0 + 1);
  m = strlen(s0 + 1);
  for (int i = 1; i <= m; i++) {
    s[i] = s0[i] - '0';
  }
  for (int i = 1; i < m; i++) {
    nxt[i][s[i + 1]] = i + 1;
    int x = !s[i + 1];
    for (int j = i - 1; ~j; j--) {
      if (same(1, j, i - j + 1, i) && s[j + 1] == x) {
        nxt[i][x] = j + 1;
        break;
      }
    }
  }
  nxt[m][0] = nxt[m][1] = m;
  nxt[0][s[1]] = 1;
  for (int w = 0; w <= m; w++) {
    f[0][0][w][w] = 1;
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= m; j++) {
      for (int k = 0; k <= m; k++) {
        for (int w = 0; w <= m; w++) {
          if (!f[i][j][k][w]) continue;
          f[i + 1][nxt[j][0]][nxt[k][0]][w] += f[i][j][k][w];
          f[i + 1][nxt[j][1]][nxt[k][1]][w] += f[i][j][k][w];
        }
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j <= m; j++) {
    ans += f[n][j][m][j];
  }
  printf("%lld\n", ans);
  return 0;
}
