Virtual contest is a way to take part in past contest, as close as possible to participation on time. It is supported only ICPC mode for virtual contests.
If you've seen these problems, a virtual contest is not for you - solve these problems in the archive.
If you just want to solve some problem from a contest, a virtual contest is not for you - solve this problem in the archive.
Never use someone else's code, read the tutorials or communicate with other person during a virtual contest.

No tag edit access

The problem statement has recently been changed. View the changes.

×
E. Appleman and a Game

time limit per test

1 secondmemory limit per test

256 megabytesinput

standard inputoutput

standard outputAppleman 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* ≤ 10^{18}). The second line contains string *t* (1 ≤ |*t*| ≤ 10^{5}). 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".

Codeforces (c) Copyright 2010-2021 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Sep/26/2021 10:59:36 (i1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|