#include <bits/stdc++.h>
using namespace std;
char s[50];
unordered_map<long long, bool> mp;
int m;
int q[50];
int qb, qf, used;
struct node {
  int nxt[2], fail, cnt;
  void clear() {
    memset(nxt, -1, sizeof nxt);
    fail = -1;
    cnt = 0;
  }
} mem[50];
struct AC_automation {
  int newnode() {
    int ans = ++used;
    mem[ans].clear();
    return ans;
  }
  void init() {
    used = -1;
    newnode();
    qb = qf = 0;
  }
  void insert(char *s, int n, int val) {
    int now = 0;
    for (int i = 0; i < n; i++) {
      if (mem[now].nxt[s[i] - '0'] == -1) mem[now].nxt[s[i] - '0'] = newnode();
      now = mem[now].nxt[s[i] - '0'];
    }
    mem[now].cnt += val;
    return;
  }
  void build() {
    mem[0].fail = 0;
    for (int i = 0; i < m; i++) {
      if (mem[0].nxt[i] == -1)
        mem[0].nxt[i] = 0;
      else {
        mem[mem[0].nxt[i]].fail = 0;
        q[qb++] = mem[0].nxt[i];
      }
    }
    while (qb > qf) {
      int u = q[qf++];
      mem[u].cnt += mem[mem[u].fail].cnt;
      for (int i = 0; i < m; i++) {
        if (mem[u].nxt[i] == -1)
          mem[u].nxt[i] = mem[mem[u].fail].nxt[i];
        else {
          mem[mem[u].nxt[i]].fail = mem[mem[u].fail].nxt[i];
          q[qb++] = mem[u].nxt[i];
        }
      }
    }
  }
} ac;
long long dp[2][50];
int main() {
  m = 2;
  int n;
  scanf("%d%s", &n, s);
  int len = strlen(s);
  if (len >= n / 2 + 3) {
    long long tmp = 0;
    for (int i = 0; i < len; i++) tmp = tmp * 2 + s[i] - '0';
    int ans = 0;
    long long val = 1LL << (n - 1);
    for (int i = 0; i < 1 << (n - len); i++) {
      long long st = tmp;
      for (int j = 0; j < n - len; j++) {
        st *= 2;
        if (i & (1 << j)) st++;
      }
      for (int j = 0; j < n; j++) {
        if (!mp.count(st)) {
          ans++;
          mp[st] = 1;
        }
        st = st / 2 + (st % 2) * val;
      }
    }
    printf("%d\n", ans);
    return 0;
  }
  long long ans = 0;
  int p = len - 1;
  for (int x = 0; x < 1 << p; x++) {
    ac.init();
    ac.insert(s, len, 1);
    ac.build();
    int ok = 0;
    dp[0][0] = 1;
    for (int j = 0; j < p; j++) {
      int v = (x >> j) & 1;
      for (int k = 0; k <= used; k++) {
        if (dp[ok][k]) {
          int kk = mem[k].nxt[v];
          if (!mem[kk].cnt) dp[ok ^ 1][kk] += dp[ok][k];
          dp[ok][k] = 0;
        }
      }
      ok ^= 1;
    }
    for (int j = 0; j < n - p; j++) {
      for (int k = 0; k <= used; k++) {
        if (dp[ok][k]) {
          for (int v = 0; v < 2; v++) {
            int kk = mem[k].nxt[v];
            if (!mem[kk].cnt) dp[ok ^ 1][kk] += dp[ok][k];
          }
          dp[ok][k] = 0;
        }
      }
      ok ^= 1;
    }
    for (int j = 0; j < p; j++) {
      int v = (x >> j) & 1;
      for (int k = 0; k <= used; k++) {
        if (dp[ok][k]) {
          int kk = mem[k].nxt[v];
          if (!mem[kk].cnt) dp[ok ^ 1][kk] += dp[ok][k];
          dp[ok][k] = 0;
        }
      }
      ok ^= 1;
    }
    ans += 1LL << (n - p);
    for (int i = 0; i <= used; i++) {
      ans -= dp[ok][i];
      dp[ok][i] = 0;
    }
  }
  printf("%I64d\n", ans);
}
