#include <bits/stdc++.h>
using namespace std;
int N, M;
string S;
int nex[42][2];
signed long long dp[42][42][2];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> S;
  M = S.size();
  for (i = 0; i < (M + 1); i++) {
    for (j = 0; j < (2); j++) {
      string T = S.substr(0, i) + (char)('0' + j);
      for (x = i + 1; x >= 0; x--) {
        if (S.substr(0, x) == T.substr(T.size() - x)) {
          nex[i][j] = x;
          break;
        }
      }
    }
  }
  signed long long ret = 0;
  for (int state = 0; state <= M; state++) {
    memset(dp, 0, sizeof(dp));
    dp[0][state][state == M] = 1;
    for (i = 0; i < (N); i++) {
      for (x = 0; x < (M + 1); x++) {
        dp[i + 1][nex[x][0]][nex[x][0] == M] += dp[i][x][0];
        dp[i + 1][nex[x][0]][1] += dp[i][x][1];
        dp[i + 1][nex[x][1]][nex[x][1] == M] += dp[i][x][0];
        dp[i + 1][nex[x][1]][1] += dp[i][x][1];
      }
    }
    ret += dp[N][state][1];
  }
  cout << ret << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
