#include <bits/stdc++.h>
using namespace std;
vector<vector<int> > automaton;
void buildAutomaton(const string& s) {
  int n = s.size(), k = 0;
  vector<int> zer(2, 0);
  for (int i = 0; i <= n; i++) automaton.push_back(zer);
  automaton[0][s[0] - '0'] = 1;
  for (int i = 1; i <= n; i++) {
    automaton[i] = automaton[k];
    if (i < n) {
      automaton[i][s[i] - '0'] = i + 1;
      k = automaton[k][s[i] - '0'];
    }
  }
}
int getState(const string& t) {
  int k = 0;
  for (char c : t) {
    k = automaton[k][c - '0'];
  }
  return k;
}
string s;
long long n;
long long dp3[44][44][44][2];
long long h(long long tar, long long rm, long long st, long long done) {
  if (st == s.size()) done = 1;
  if (rm == 0) return done && tar == st;
  if (dp3[tar][rm][st][done] != -1) return dp3[tar][rm][st][done];
  return dp3[tar][rm][st][done] = h(tar, rm - 1, automaton[st][0], done) +
                                  h(tar, rm - 1, automaton[st][1], done);
}
int main() {
  memset(dp3, -1, sizeof dp3);
  cin >> n >> s;
  buildAutomaton(s);
  long long ans = 0;
  for (long long i = 0; i <= s.size(); i++) ans += h(i, n, i, 0);
  cout << ans << endl;
  return 0;
}
