God of the Vile Baskers

No attempts yetTime limit1sMemory limit128 MB

Problem

A little-known writer, Arthur Conan Moyle, has finally worked out why his books are not as popular as he believes they deserve to be. He noticed that his work becomes tedious because the same or very similar passages of text keep recurring. He decided that the best way to improve his books is to throw away everything from the first repetition onward — the books then acquire an intriguing, open-ended feeling.

At first he looked for exactly identical passages, but that failed: repeated passages rarely match precisely. Some letters that are lowercase the first time may be uppercase the second time and vice versa, the punctuation may differ slightly, and the words in a sentence may appear in a slightly different order. To cope with this, he devised the following, more forgiving rule for recognizing duplicates. It has a parameter $k$ (a positive integer); changing $k$ controls how long a repeated passage may be while still being treated as a duplicate.

The alphabetic characters are the letters az and AZ. Case is ignored, so a and A count as the same letter.

Two strings $S_1$ and $S_2$ are $k$-identical up to a permutation of letters if:

  • both $S_1$ and $S_2$ start and end with an alphabetic character;
  • both $S_1$ and $S_2$ contain exactly $k$ alphabetic characters;
  • for every alphabetic character $c$, string $S_1$ contains the same number of occurrences of $c$ as string $S_2$.

In other words, if $S_1$ and $S_2$ are $k$-identical up to a permutation of letters, they use exactly the same alphabetic characters (counting multiplicity), though possibly in a different order.

Given one of the writer's books, find the longest initial part that does not contain two substrings that are $k$-identical up to a permutation of letters.

Input

The input contains several test cases. Each test case is given on two lines.

The first line contains an integer $k$ with $1 \le k \le 50$.

The second line contains the string $T$. The length of $T$ is at most $100,000$ characters. $T$ may contain non-alphabetic characters, including spaces, but it contains no character with a special meaning (that is, no character whose ASCII code is smaller than $32$).

The input ends with a line containing a single zero.

Output

For each test case, print one line. For the $i$-th test case, output a single integer: the length of the longest prefix $P$ (including all non-alphabetic characters) of that test case's string $T$ such that $P$ does not contain two distinct — but not necessarily non-overlapping — substrings $S_1$ and $S_2$ that are $k$-identical up to a permutation of letters.