#include <bits/stdc++.h>
using namespace std;
void dbg() { cerr << '\n'; }
template <typename T, typename... A>
void dbg(T _, A... a) {
  cerr << ' ' << _;
  dbg(a...);
}
const int maxn = 43, INF = 0x3f3f3f3f;
int n;
string s;
int fail[maxn], pos[maxn][2];
void Getfail() {
  for (int i = (2); i <= (((int)(s).size() - 1)); ++i) {
    int j = fail[i - 1];
    while (j && s[j + 1] != s[i]) j = fail[j];
    if (s[j + 1] == s[i]) fail[i] = j + 1;
  }
  for (int i = (0); i <= (((int)(s).size() - 1)); ++i) {
    for (int j = ('0'); j <= ('1'); ++j) {
      int k = i;
      while (k && s[k + 1] != j) k = fail[k];
      if (s[k + 1] == j) pos[i][j - '0'] = k + 1;
    }
  }
}
long long f[maxn][maxn][maxn][2];
long long Dfs(int n, int now, int ed, bool flag) {
  if (now == ((int)(s).size() - 1)) flag = 1;
  if (!n) return now == ed && flag;
  long long &ans = f[n][now][ed][flag];
  if (~ans) return ans;
  ans = 0;
  for (int i = (0); i <= (1); ++i) {
    ans += Dfs(n - 1, pos[now][i], ed, flag);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> s;
  s = ' ' + s;
  Getfail();
  long long ans = 0;
  memset(f, -1, sizeof f);
  for (int i = (0); i <= (((int)(s).size() - 1)); ++i) {
    ans += Dfs(n, i, i, 0);
  }
  cout << ans << '\n';
  return 0;
}
