#include <bits/stdc++.h>
using namespace std;
const int N = 42;
long long dp[N][N];
int f[N], n;
string s;
long long Solve(int x) {
  memset(dp, 0, sizeof dp);
  dp[0][x] = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < s.size(); j++) {
      int m = j;
      while (m && s[m] != '0') m = f[m];
      if (s[m] == '0') m++;
      dp[i + 1][m] += dp[i][j];
      m = j;
      while (m && s[m] != '1') m = f[m];
      if (s[m] == '1') m++;
      dp[i + 1][m] += dp[i][j];
    }
  }
  return dp[n][x];
}
int main() {
  cin >> n >> s;
  for (int i = 2; i <= s.size(); i++) {
    f[i] = f[i - 1];
    while (f[i] && s[f[i]] != s[i - 1]) f[i] = f[f[i]];
    if (s[f[i]] == s[i - 1]) f[i]++;
  }
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) ans += Solve(i);
  cout << (1ll << n) - ans << "\n";
}
