#include <bits/stdc++.h>
using namespace std;
string str;
int lps[200010];
void make_lps(string pattern) {
  int n = pattern.size();
  lps[0] = lps[1] = 0;
  for (int i = 2; i <= n; i++) {
    int p = lps[i - 1];
    while (true) {
      if (pattern[i - 1] == pattern[p]) {
        lps[i] = p + 1;
        break;
      }
      if (p == 0)
        break;
      else
        p = lps[p];
    }
  }
}
long long dp[44][44][44][2], n, m;
long long rec(int p, int v, int c, int t) {
  if (p == n) return t & c == v;
  long long &temp = dp[p][v][c][t];
  if (temp != -1) return temp;
  temp = 0;
  int a;
  for (a = c; str[a] != '0'; a = lps[a])
    if (a == 0) {
      a = -1;
      break;
    }
  int b;
  for (b = c; str[b] != '1'; b = lps[b])
    if (b == 0) {
      b = -1;
      break;
    }
  temp = rec(p + 1, v, a + 1, (a + 1 == m) ? 1 : t) +
         rec(p + 1, v, b + 1, (b + 1 == m) ? 1 : t);
  return temp;
}
int main() {
  ios::sync_with_stdio(false);
  memset(dp, -1, sizeof(dp));
  int d = 0;
  cin >> n;
  cin >> str;
  m = str.size();
  make_lps(str);
  long long prin = 0;
  for (int i = 0; i <= m; i++) prin += rec(0, i, i, 0);
  cout << prin << endl;
  return 0;
}
