#include <bits/stdc++.h>
using namespace std;
const int N = 42;
class Solution {
 public:
  long long count(string& _s, int n) {
    long long res = 0;
    memset(dp, -1, sizeof(dp));
    s = _s;
    nextTable = buildNextTable(s);
    for (int i = 0; i <= s.size(); ++i) {
      res += slove(n, i, i, 0);
    }
    return res;
  }

 private:
  long long dp[N][N][N][2];
  string s;
  vector<int> nextTable;
  vector<int> buildNextTable(string& s) {
    int n = s.length();
    vector<int> res(n + 1, 0);
    for (int i = 1, j = 0; i < n; ++i) {
      while (j != 0 && s[j] != s[i]) {
        j = res[j - 1];
      }
      if (s[j] == s[i]) {
        ++j;
      }
      res[i] = j;
    }
    return res;
  }
  int getNext(int cur, char ch) {
    if (cur == s.length()) {
      cur = nextTable[s.length() - 1];
    }
    while (cur != 0 && s[cur] != ch) {
      cur = nextTable[cur - 1];
    }
    if (s[cur] == ch) {
      ++cur;
    }
    return cur;
  }
  long long slove(int n, int cur, int end, bool done) {
    if (cur == s.length()) {
      done = true;
    }
    if (n == 0) {
      return done && (cur == end) ? 1 : 0;
    }
    long long& res = dp[n][cur][end][done];
    if (res >= 0) {
      return res;
    }
    res = 0;
    for (auto c : string("01")) {
      int next = getNext(cur, c);
      res += slove(n - 1, next, end, done);
    }
    return res;
  }
};
int main(int argc, char** argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  string s;
  cin >> s;
  Solution sol;
  cout << sol.count(s, n) << endl;
  return 0;
}
