#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
int n, m;
int p[64], a[64][2], x[64];
long long dp[64][64][64][2];
void kmp(string &cad) {
  p[0] = 0;
  for (int i = 1; i < m; ++i) {
    p[i] = p[i - 1];
    while (p[i] > 0 and cad[p[i]] != cad[i]) p[i] = p[p[i] - 1];
    if (cad[p[i]] == cad[i]) p[i]++;
  }
  for (int i = m - 1; i >= 0; --i) p[i + 1] = p[i];
}
long long solve(int k, int i, int j, int has) {
  long long &ans = dp[k][i][j][has];
  if (ans != -1) return ans;
  if (i == n) return ans = ((k == j) and has);
  ans = 0;
  for (int t = int(0); t < int(2); ++t)
    ans += solve(k, i + 1, a[j][t], has || (a[j][t] == m));
  return ans;
}
int main() {
  string cad;
  cin >> n >> cad;
  m = int(cad.size());
  for (int i = 0; i < m; ++i) x[i] = cad[i] - '0';
  kmp(cad);
  a[0][x[0]] = 1;
  a[0][x[0] ^ 1] = 0;
  for (int i = 1; i < m; ++i) {
    a[i][x[i]] = i + 1;
    a[i][x[i] ^ 1] = a[p[i]][x[i] ^ 1];
  }
  a[m][0] = a[p[m]][0];
  a[m][1] = a[p[m]][1];
  memset(dp, -1, sizeof(dp));
  long long ans = 0;
  for (int i = int(0); i < int(m + 1); ++i) ans += solve(i, 0, i, 0);
  cout << ans << endl;
  return 0;
}
