#include <bits/stdc++.h>
const int N = 50;
int n, m, next[N], transfer[N][2];
std::string s;
long long dp[N][N];
int main() {
  std::ios::sync_with_stdio(0), std::cin.tie(0);
  std::cin >> n >> s, m = s.size();
  for (int i = 1, j = next[0] = -1; i <= m; next[i++] = ++j)
    while (j >= 0 && s[j] != s[i - 1]) j = next[j];
  for (int i = 0; i < m; ++i) {
    transfer[i][s[i] ^ '0'] = i + 1;
    transfer[i][s[i] ^ '1'] = transfer[next[i]][s[i] ^ '1'];
  }
  transfer[m][0] = transfer[m][1] = m;
  long long ans = 1LL << n;
  for (int i = 0; i < m; ++i) {
    std::memset(dp, 0, sizeof dp), dp[0][i] = 1;
    for (int l = 0; l < n; ++l)
      for (int p = 0; p < m; ++p)
        for (int v = 0; v < 2; ++v) dp[l + 1][transfer[p][v]] += dp[l][p];
    ans -= dp[n][i];
  }
  std::cout << ans << '\n';
  return 0;
}
