#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 7;
template <class T>
void dbs(string str, T t) {
  cout << str << " : " << t << endl;
}
template <class T, class... second>
void dbs(string str, T t, second... s) {
  int idx = str.find(',');
  cout << str.substr(0, idx) << " : " << t << ",";
  dbs(str.substr(idx + 1), s...);
}
template <class second, class T>
ostream& operator<<(ostream& os, const pair<second, T>& p) {
  return os << "(" << p.first << ", " << p.second << ")";
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
ostream& operator<<(ostream& os, const set<T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class second, class T>
ostream& operator<<(ostream& os, const map<second, T>& p) {
  os << "[ ";
  for (auto& it : p) os << it << " ";
  return os << "]";
}
template <class T>
void prc(T a, T b) {
  cout << "[";
  for (T i = a; i != b; ++i) {
    if (i != a) cout << ", ";
    cout << *i;
  }
  cout << "]";
  cout << endl;
}
vector<int> fail(const string& s) {
  int n = int(s.size());
  vector<int> f(n);
  for (auto i = (1); i <= (n - 1); ++i) {
    f[i] = f[i - 1];
    while (s[f[i]] != s[i]) {
      if (f[i] == 0) break;
      f[i] = f[f[i] - 1];
    }
    if (s[f[i]] == s[i]) f[i]++;
  }
  return f;
}
string s;
vector<int> first;
int getNext(int now, int ch) {
  int x = now;
  if (now == int(s.size())) now = first[now - 1];
  while (s[now] != ch) {
    if (now == 0) return 0;
    now = first[now - 1];
  }
  return now + 1;
}
vector<int> prv[41][2];
long long dp[2][41][41];
long long f(int n, int cur) {
  if (n == 0) return cur == int(s.size());
  long long& ans = dp[0][n][cur];
  if (~ans) return ans;
  ans = 0;
  for (auto i = ('0'); i <= ('1'); ++i) {
    int nxt = getNext(cur, i);
    if (n - 1 > 0 and nxt == int(s.size())) continue;
    ans += f(n - 1, nxt);
  }
  return ans;
}
long long g(int n, int cur) {
  if (n == 0) return cur == int(s.size());
  long long& ans = dp[1][n][cur];
  if (~ans) return ans;
  ans = 0;
  for (auto i = (0); i <= (1); ++i) {
    for (int nxt : prv[cur][i]) ans += g(n - 1, nxt);
  }
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  cin >> s;
  first = fail(s);
  memset(dp, -1, sizeof dp);
  for (auto i = (0); i <= (int(s.size())); ++i)
    for (auto j = (0); j <= (1); ++j) prv[getNext(i, j + '0')][j].push_back(i);
  long long ans = 0;
  for (auto i = (0); i <= (int(s.size())); ++i) {
    for (auto pos = (0); pos <= (n - 1); ++pos) {
      ans += f(pos + 1, i) * g(n - (pos + 1), i);
    }
  }
  cout << ans;
  return 0;
}
