#include <bits/stdc++.h>
using namespace std;
int suf[2000][2], pre[2000][2], preok[2000], len[2000];
int n;
string s;
long long dp[45][45][45 * 45];
long long pwr[45];
inline long long hudai(string t, int f) {
  for (int i = 0; i < f; i++) t.push_back(t[i]);
  int lps[100];
  lps[0] = 0;
  int i = 1, j = 0;
  while (i < s.length()) {
    if (s[i] == s[j]) {
      j++;
      lps[i] = j;
      i++;
    } else {
      if (j) {
        j = lps[j - 1];
      } else {
        lps[i] = 0;
        i++;
      }
    }
  }
  i = 0, j = 0;
  int cnt = 0;
  while (i < t.length()) {
    if (t[i] == s[j]) {
      i++;
      j++;
    }
    if (j == s.length()) {
      return 1ll;
    } else if (i < t.length() && t[i] != s[j]) {
      if (j)
        j = lps[j - 1];
      else
        i++;
    }
  }
  return 0ll;
}
inline int prequery(string t) {
  int u = 0;
  int ret = 0;
  for (int i = 0; i < t.length(); i++) {
    int v = t[i] - '0';
    if (!pre[u][v]) break;
    u = pre[u][v];
    if (preok[u]) ret = i + 1;
  }
  return ret;
}
inline int sufquery(string t) {
  int u = 0;
  reverse(t.begin(), t.end());
  int ret = 0;
  for (int i = 0; i < t.length(); i++) {
    int v = t[i] - '0';
    if (!suf[u][v]) break;
    u = suf[u][v];
  }
  return u;
}
inline long long solve(int i, int f, int l, string t) {
  if (len[l] == s.length()) {
    return pwr[n - i];
  }
  if (i == n) {
    return hudai(t, f);
  }
  long long &ret = dp[i][f][l];
  if (ret != -1ll) {
    return ret;
  }
  ret = 0ll;
  ret += solve(i + 1, prequery(t + "0"), sufquery(t + "0"), t + "0");
  ret += solve(i + 1, prequery(t + "1"), sufquery(t + "1"), t + "1");
  return ret;
}
int main() {
  memset((dp), (-1), sizeof((dp)));
  ;
  cin >> n;
  cin >> s;
  int cnt = 0;
  pwr[0] = 1ll;
  for (int i = 1; i <= 40; i++) pwr[i] = pwr[i - 1] * 2ll;
  for (int i = 0; i < s.length(); i++) {
    int u = 0;
    for (int j = i; j < s.length(); j++) {
      int v = s[j] - '0';
      if (pre[u][v] == 0) pre[u][v] = ++cnt;
      u = pre[u][v];
    }
    preok[u] = 1;
  }
  cnt = 0;
  reverse(s.begin(), s.end());
  len[0] = 0;
  for (int i = 0; i < s.length(); i++) {
    int u = 0;
    for (int j = i; j < s.length(); j++) {
      int v = s[j] - '0';
      if (suf[u][v] == 0) suf[u][v] = ++cnt;
      len[suf[u][v]] = len[u] + 1;
      u = suf[u][v];
    }
  }
  reverse(s.begin(), s.end());
  cout << solve(0, 0, 0, "") << endl;
  return 0;
}
