#include <bits/stdc++.h>
const int MAXN = 50;
int n;
char buf[MAXN];
int fail[MAXN], tr[MAXN][2];
long long dp[MAXN][MAXN][MAXN];
int main() {
  std::ios_base::sync_with_stdio(false), std::cin.tie(0);
  std::cin >> n >> buf + 1;
  int S = strlen(buf + 1);
  for (int i = 1; i <= S; ++i) {
    int now = fail[i - 1];
    while (now && (now + 1 == i || buf[now + 1] != buf[i])) now = fail[now];
    fail[i] = now + 1 != i && buf[now + 1] == buf[i] ? now + 1 : 0;
  }
  for (int i = 0; i < S; ++i)
    for (int j = 0; j < 2; ++j) {
      int now = i;
      while (now && buf[now + 1] != j + '0') now = fail[now];
      tr[i][j] = buf[now + 1] == j + '0' ? now + 1 : 0;
    }
  for (int i = 0; i < S; ++i) dp[0][i][i] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < S; ++j)
      for (int k = 0; k < S; ++k) {
        dp[i][j][tr[k][0]] += dp[i - 1][j][k];
        dp[i][j][tr[k][1]] += dp[i - 1][j][k];
      }
  }
  long long ans = 1ll << n;
  for (int i = 0; i < S; ++i) ans -= dp[n][i][i];
  std::cout << ans << std::endl;
  return 0;
}
