#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "YES" : "NO");
  exit(0);
}
void addmod(int& x, int y, int mod = 1000000007) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et(int x = -1) {
  printf("%d\n", x);
  exit(0);
}
long long fastPow(long long x, long long y, long long mod = 1000000007) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
char s[105];
const int maxn = 105;
struct Aca {
  int next[maxn][26], fail[maxn];
  int end[maxn];
  int root, L;
  int newNode() {
    for (int i = 0; i < 26; i++) next[L][i] = -1;
    end[L++] = 0;
    return L - 1;
  }
  void init() {
    L = 0;
    root = newNode();
  }
  void insert(char str[], int len) {
    int now = root;
    for (int i = 0; i < len; i++) {
      int temp = str[i] - '0';
      if (next[now][temp] == -1) {
        next[now][temp] = newNode();
      }
      now = next[now][temp];
    }
  }
  void build() {
    queue<int> que;
    fail[root] = root;
    for (int i = 0; i < 26; i++) {
      if (next[root][i] == -1) {
        next[root][i] = root;
      } else {
        fail[next[root][i]] = root;
        que.push(next[root][i]);
      }
    }
    while (!que.empty()) {
      int now = que.front();
      que.pop();
      end[now] += end[fail[now]];
      for (int i = 0; i < 26; i++) {
        int t = next[now][i];
        if (t == -1) {
          next[now][i] = next[fail[now]][i];
        } else {
          fail[t] = next[fail[now]][i];
          que.push(t);
        }
      }
    }
  }
  long long dp[44][44][44];
  void cal(int n) {
    long long ans = 1LL << n;
    for (int(i) = 0; (i) < (int)(L - 1); (i)++) {
      memset(dp, 0, sizeof dp);
      dp[0][0][i] = 1;
      for (int j = 0; j < n; j++) {
        for (int(l) = 0; (l) < (int)(L - 1); (l)++)
          for (int(k) = 0; (k) < (int)(L - 1); (k)++)
            if (dp[j][l][k]) {
              for (int(v) = 0; (v) < (int)(2); (v)++) {
                int a = next[l][v], b = next[k][v];
                if (a == L - 1 || b == L - 1) continue;
                dp[j + 1][a][b] += dp[j][l][k];
              }
            }
      }
      for (int(l) = 0; (l) < (int)(L - 1); (l)++) ans -= dp[n][i][l];
    }
    printf("%lld\n", ans);
  }
} ac;
void fmain(int ID) {
  scanf("%d", &n);
  scanf("%s", s);
  ac.init();
  ac.insert(s, strlen(s));
  ac.build();
  ac.cal(n);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
