#include <bits/stdc++.h>
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long double eps = 1e-7;
const int inf = 1000000010;
const long long INF = 10000000000000010LL;
const int mod = 1000000007;
const int N = 45;
int n, m, k, u, v, x, y, t, a, b;
int S[N], f[N], nex[N][2];
long long dp[N][N], ans;
string s;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> s;
  m = s.size();
  for (int i = 1; i <= m; i++) S[i] = s[i - 1] - '0';
  nex[0][S[1]] = 1;
  for (int i = 1; i < m; i++) {
    nex[i][S[i + 1]] = i + 1;
    nex[i][S[i + 1] ^ 1] = nex[f[i]][S[i + 1] ^ 1];
    f[i + 1] = nex[f[i]][S[i + 1]];
  }
  nex[m][0] = nex[f[m]][0];
  nex[m][1] = nex[f[m]][1];
  for (int i = 0; i < m; i++) {
    memset(dp, 0, sizeof(dp));
    dp[0][i] = 1;
    for (int j = 0; j < n; j++)
      for (int k = 0; k < m; k++) {
        dp[j + 1][nex[k][0]] += dp[j][k];
        dp[j + 1][nex[k][1]] += dp[j][k];
      }
    ans += dp[n][i];
  }
  cout << (1ll << n) - ans << '\n';
  return 0;
}
