#include <bits/stdc++.h>
using namespace std;
long long inline read() {
  long long num = 0, neg = 1;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    num = (num << 3) + (num << 1) + c - '0';
    c = getchar();
  }
  return num * neg;
}
const long long maxn = 110, mod = 998244353;
long long n, m, nxt[maxn], ANS = 1, a[maxn];
char str[maxn];
struct Mat {
  long long a[50][50];
  Mat() { memset(a, 0, sizeof(a)); }
} trans;
Mat operator*(Mat x, Mat y) {
  Mat ans;
  for (long long i = 0; i < m; i++)
    for (long long j = 0; j < m; j++)
      for (long long k = 0; k < m; k++)
        ans.a[i][j] = ans.a[i][j] + x.a[i][k] * y.a[k][j];
  return ans;
}
void ksm(Mat x, long long y) {
  Mat ans;
  for (long long i = 0; i < m; i++) ans.a[i][i] = 1;
  while (y) {
    if (y & 1) ans = ans * x;
    x = x * x;
    y >>= 1;
  }
  for (long long i = 0; i < m; i++) ANS -= ans.a[i][i];
  cout << ANS;
}
signed main() {
  n = read();
  scanf("%s", str + 1);
  m = strlen(str + 1);
  long long pl = 0;
  for (long long i = 1; i <= n; i++) a[i] = str[i] - '0';
  for (long long i = 1; i <= n; i++) ANS = ANS * 2;
  for (long long i = 2; i <= m; i++) {
    while (pl && a[pl + 1] != a[i]) pl = nxt[pl];
    if (a[pl + 1] == a[i]) pl++;
    nxt[i] = pl;
  }
  for (long long i = 0; i < m; i++) trans.a[i][i + 1] = 1;
  trans.a[0][0] = 1;
  for (long long i = 1; i < m; i++) {
    long long pl = i;
    while (pl && a[pl + 1] != (a[i + 1] ^ 1)) pl = nxt[pl];
    if (a[pl + 1] == (a[i + 1] ^ 1)) pl++;
    trans.a[i][pl] = 1;
  }
  ksm(trans, n);
  return 0;
}
