#include <bits/stdc++.h>
using namespace std;
int n;
string s;
vector<string> substr;
map<string, int> cnt;
const int N = 45;
long long dp[N][N][2][N * N];
void add(int len, int pre, int hav, int suf, char ch) {
  string tmp = s.substr(0, pre);
  tmp += ch;
  while (s.substr(0, tmp.size()) != tmp) {
    tmp = tmp.substr(1);
  }
  int nextpre = tmp.size();
  int nexthav = tmp == s ? 1 : hav;
  int nextsuf = suf;
  if (substr[suf].size() == len) {
    tmp = substr[suf];
    tmp += ch;
    if (cnt.count(tmp)) nextsuf = cnt[tmp];
  }
  dp[len + 1][nextpre][nexthav][nextsuf] += dp[len][pre][hav][suf];
}
long long solve(int len, int pre, int hav, int suf) {
  if (dp[len][pre][hav][suf] == 0) {
    return 0;
  } else if (len == n) {
    if (hav)
      return dp[len][pre][hav][suf];
    else {
      string tmp = s.substr(0, pre) + substr[suf];
      if (tmp.find(s) != string::npos)
        return dp[len][pre][hav][suf];
      else
        return 0;
    }
  } else {
    add(len, pre, hav, suf, '0');
    add(len, pre, hav, suf, '1');
    return 0;
  }
}
int main() {
  cin >> n >> s;
  cnt[""] = 0;
  substr.push_back("");
  for (int len = 1; len <= s.size(); len += 1) {
    for (int i = 0; i + len <= s.size(); i += 1) {
      string sstr = s.substr(i, len);
      if (cnt.count(sstr) == 0) {
        cnt[sstr] = substr.size();
        substr.push_back(sstr);
      }
    }
  }
  long long ans = 0;
  dp[0][0][0][0] = 1;
  for (int len = 0; len <= n; len += 1) {
    for (int pre = 0; pre <= len; pre += 1) {
      for (int hav = 0; hav < 2; hav += 1) {
        for (int i = 0; i < substr.size(); i += 1) {
          if (substr[i].size() > len + 1) break;
          ans += solve(len, pre, hav, i);
        }
      }
    }
  }
  cout << ans << endl;
}
