Appleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings s and t both consisting only of letters 'A', 'B', 'C', 'D'. Then Appleman must build string s as quickly as possible. Initially he has empty string, and in one second he can append to end of the current string any contiguous substring of t.

Now, Toastman and Appleman are beginning to play the game. Toastman has already told string t to Appleman, but he hasn't come up with string s yet. Toastman only thinks, that he should choose string s consisting of n characters. Of course, he wants to find the worst string for Appleman (such string, that Appleman will spend as much time as possible during the game). Tell Toastman, how much time will Appleman spend during the game if Toastman finds the worst string for him. You can assume that Appleman plays optimally, therefore he builds any string s in minimal possible time.

Input

The first line contains an integer n (1 ≤ n ≤ 1018). The second line contains string t (1 ≤ |t| ≤ 105). String t consists of only letters 'A', 'B', 'C', 'D'. Each letter appears at least once in string t.

Output

Print a single integer — the largest possible time Appleman needs.

Examples

Input

5
ABCCAD


Output

5


Input

5
AAABACADBABBBCBDCACBCCCDDDBDCDD


Output

4

Note

In the first example, Toastman can choose s equal to "AAAAA".

In the second example, Toastman can choose s equal to "DADDA".
#include <bits/stdc++.h>
using namespace std;
long long N;
char s[100005];
int M, D, A[3000005][4];
struct Mat {
  long long A[4][4];
  Mat() { memset(A, 0, sizeof(A)); }
  Mat operator*(const Mat& b) {
    Mat c;
    for (int i = 0; i <= 3; i++)
      for (int j = 0; j <= 3; j++) {
        c.A[i][j] = (1ll << 60);
        for (int k = 0; k <= 3; k++)
          c.A[i][j] = min(c.A[i][j], A[i][k] + b.A[k][j]);
      }
    return c;
  }
  Mat operator^(long long k) {
    Mat ret, a = *this;
    for (; k; k >>= 1, a = a * a)
      if (k & 1) ret = ret * a;
    return ret;
  }
} S;
void DFS(int u, int s, int d) {
  for (int i = 0; i <= 3; i++)
    if (A[u][i])
      DFS(A[u][i], s, d + 1);
    else
      S.A[s][i] = min(S.A[s][i], 1ll * d);
}
bool check(long long K) {
  Mat ret = S ^ K;
  long long x = 1ll << 60;
  for (int i = 0; i <= 3; i++)
    for (int j = 0; j <= 3; j++) x = min(x, ret.A[i][j]);
  return x < N;
}
int main() {
  scanf("%I64d%s", &N, s + 1);
  M = strlen(s + 1);
  for (int i = 1; i <= M; i++) {
    for (int x = 0, j = i; j <= i + 30 && j <= M; x = A[x][s[j] - 'A'], j++)
      if (!A[x][s[j] - 'A']) A[x][s[j] - 'A'] = ++D;
  }
  long long L = 0, R = N;
  for (int i = 0; i <= 3; i++)
    for (int j = 0; j <= 3; j++) S.A[i][j] = (1ll << 60);
  for (int i = 0; i <= 3; i++)
    if (A[0][i]) DFS(A[0][i], i, 1);
  for (; L + 1 < R;) {
    long long Mid = L + R >> 1;
    check(Mid) ? L = Mid : R = Mid;
  }
  printf("%I64d\n", L + 1);
}
