#include <bits/stdc++.h>
using namespace std;
int n, m, a[100][100], p[100];
long long f[100][100][100], ans;
char s[1000];
int main() {
  scanf("%d%s", &n, s + 1);
  m = strlen(s + 1);
  for (int i = 1; i <= m; i++) a[i - 1][s[i] - 48] = i;
  for (int i = 1; i <= m; i++)
    for (int j = 0; j < 2; j++)
      if (a[i][j])
        p[a[i][j]] = a[p[i]][j];
      else
        a[i][j] = a[p[i]][j];
  ans = 1ll << n;
  for (int i = 0; i < m; i++) {
    for (int j = 0; j <= n; j++)
      for (int ij = 0; ij < m; ij++)
        for (int ji = 0; ji < m; ji++) f[j][ij][ji] = 0;
    f[0][0][i] = 1;
    for (int j = 0; j < n; j++)
      for (int ij = 0; ij < m; ij++)
        for (int ji = 0; ji < m; ji++)
          for (int k = 0; k < 2; k++)
            f[j + 1][a[ij][k]][a[ji][k]] += f[j][ij][ji];
    for (int j = 0; j < m; j++) ans -= f[n][i][j];
  }
  printf("%lld", ans);
  return 0;
}
