#include <bits/stdc++.h>
using namespace std;
using namespace rel_ops;
using ll = int64_t;
using Pii = pair<int, int>;
using ull = uint64_t;
using Vi = vector<int>;
void run();
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  run();
  return 0;
}
int uplg(int n) { return 32 - __builtin_clz(n); }
int uplg(ll n) { return 64 - __builtin_clzll(n); }
void run() {
  int n, m;
  string pattern;
  Vi valid;
  cin >> n >> pattern;
  m = int((pattern).size());
  for (int i = (0); i < (n); i++) {
    bool ok = true;
    for (int j = (0); j < (m); j++) {
      int k = (i + j) % n;
      if (k < m && pattern[j] != pattern[k]) {
        ok = false;
        break;
      }
    }
    if (ok) valid.push_back(i);
  }
  ll ans = 0;
  vector<ll> dp(n);
  dp[0] = 1;
  for (auto& k : (valid)) {
    if (k > 0) {
      for (auto& j : (valid)) {
        int i = (k + j) % n;
        if (i < k) {
          dp[k] -= dp[i] << max(0, k - i - m);
        }
      }
    }
    ans += (dp[k] * (n - k)) << max(0, n - k - m);
  }
  cout << ans << endl;
}
