#include <bits/stdc++.h>
using namespace std;
const int N = 41;
vector<int> kmp;
string s;
void prefix_function() {
  for (int i = 1; i < (int)s.size(); ++i) {
    int j = kmp[i - 1];
    while (j > 0 && s[j] != s[i]) {
      j = kmp[j - 1];
    }
    if (s[j] == s[i]) j++;
    kmp[i] = j;
  }
}
int memGo[N][2];
int goKmp(int st, char c) {
  auto& cur = memGo[st][c - '0'];
  if (cur != -1) return cur;
  if (st == (int)s.size()) st = kmp[st - 1];
  if (st > 0 && s[st] != c) {
    st = kmp[st - 1];
    return cur = goKmp(st, c), cur;
  }
  cur = st;
  if (s[cur] == c) cur++;
  return cur;
}
long long dp[N][N][N][2];
long long fnd(int len, int v, int en, int good) {
  long long& ans = dp[len][v][en][good];
  if (ans != -1) {
    return ans;
  }
  if (v == (int)s.size()) good = true;
  if (len == 0) {
    ans = ((v == en) and good);
    return ans;
  }
  ans = 0;
  for (int i = 0; i < 2; ++i) {
    ans += fnd(len - 1, goKmp(v, i + '0'), en, good);
  }
  return ans;
}
int n;
int main() {
  cin >> n >> s;
  kmp.resize((int)s.size());
  prefix_function();
  memset(memGo, -1, sizeof(memGo));
  memset(dp, -1, sizeof(dp));
  long long ans = 0;
  for (int i = 0; i <= (int)s.size(); i++) {
    ans += fnd(n, i, i, 0);
  }
  cout << ans << endl;
  return 0;
}
