#include <bits/stdc++.h>
using namespace std;
long long d[50][50][50];
long long d2[50][50][50];
long long n;
string s;
long long chk(long long a, long long b, long long c, long long x) {
  vector<char> v(a, -1);
  for (long long i = 0; i < s.size(); i++) {
    v[(a - s.size() + x + i) % a] = s[i];
  }
  bool ok = true;
  for (long long i = 0; i < b; i++) {
    if (v[i] != -1 && v[i] != s[s.size() - b + i]) {
      ok = false;
      if (false) cerr << "fail1" << endl;
    }
    v[i] = s[s.size() - b + i];
  }
  for (long long i = 0; i < c; i++) {
    if (v[a - c + i] != -1 && v[a - c + i] != s[i]) {
      ok = false;
      if (false) cerr << "fail2" << endl;
    }
    v[a - c + i] = s[i];
  }
  long long cnt = 0;
  for (long long i = 0; i < a; i++) {
    if (v[i] == -1) {
      cnt++;
    }
  }
  if (false) cerr << "v: ";
  for (long long i = 0; i < a; i++) {
    if (false) cerr << v[i];
  }
  if (false) cerr << endl;
  if (ok) {
    return cnt;
  } else {
    return -1;
  }
}
long long dp(long long a, long long b, long long c) {
  if (d[a][b][c] != -1) {
    return d[a][b][c];
  }
  long long ret = 0;
  if (a >= s.size()) {
    if (c == 0) {
      ret = dp(a - 1, b, 0) * 2;
    } else {
      ret = dp(a - 1, b, c - 1);
    }
    long long cnt = chk(a, b, c, 0);
    if (cnt != -1) {
      ret += (1LL << cnt) - dp(a - 1, b, s.size() - 1);
    }
    if (false)
      cerr << a << " " << b << " " << c << " " << ret << " " << cnt << endl;
  }
  d[a][b][c] = ret;
  if (ret < 0) {
    abort();
  }
  return ret;
}
long long dp2(long long x, long long b, long long c) {
  if (d2[x][b][c] != -1) {
    return d2[x][b][c];
  }
  long long ret;
  if (x == 0) {
    ret = dp(n, b, c);
  } else {
    ret = dp2(x - 1, b, c);
    long long cnt = chk(n, b, c, x);
    if (cnt != -1) {
      ret += (1LL << cnt);
      ret -= dp2(x - 1, max(b, x), max(c, (long long)s.size() - x));
    }
  }
  if (false) cerr << x << " " << b << " " << c << " " << ret << endl;
  d2[x][b][c] = ret;
  if (ret < 0) {
    abort();
  }
  return ret;
}
int main() {
  cin >> n >> s;
  for (long long a = 0; a < 50; a++) {
    for (long long b = 0; b < 50; b++) {
      for (long long c = 0; c < 50; c++) {
        d[a][b][c] = -1;
        d2[a][b][c] = -1;
      }
    }
  }
  cout << dp2(s.size() - 1, 0, 0) << endl;
}
