Colored Stones

No attempts yetTime limit1sMemory limit128 MB

Problem

You are given a row of mm stones, each painted with one of kk colors. You want to remove some stones so that no two stones of the same color are separated by a stone of a different color — in other words, when the remaining stones are read from left to right, all stones of each color form a single contiguous block. You may not reorder the stones; you may only remove them. Find the minimum number of stones you must remove.

Input

The input consists of several test cases. The first line of each test case contains two integers mm and kk (1m1001 \le m \le 100, 1k51 \le k \le 5). The next line contains mm integers x1,,xmx_1, \ldots, x_m, each from the set {1,,k}\{1, \ldots, k\}, giving the color of every stone. The end of input is marked by a line with m=k=0m = k = 0, which must not be processed.

Output

For each test case, print on its own line the minimum number of stones that must be removed to satisfy the condition.

Hint

For example, if the stone colors are 2 1 2 2 1 1 3 1 3 3, removing the 2nd and 7th stones leaves 2 2 2 1 1 1 3 3 — three 2s, three 1s, and two 3s, each grouped into a single block — so the minimum number of removals is 2. Other optimal solutions may exist.