#arc126d. [arc126_d]Pure Straight

[arc126_d]Pure Straight

Problem Statement

Given is a sequence of NN positive integers A=(A1,A2,ldots,AN)A = (A_1, A_2, \\ldots, A_N), where each AiA_i is 11, 22, ldots\\ldots, or KK.

You can do the following operation on this sequence any number of times.

  • Swap two adjacent elements, that is, choose ii and jj such that ij=1|i-j|=1 and swap AiA_i and AjA_j.

Find the minimum number of operations needed to make AA satisfy the following condition.

  • AA contains (1,2,ldots,K)(1, 2, \\ldots, K) as a contiguous subsequence, that is, there is a positive integer nn at most NK+1N-K+1 such that An=1A_n = 1, An+1=2A_{n+1} = 2, ldots\\ldots, and An+K1=KA_{n+K-1} = K.

Constraints

  • 2leqKleq162\\leq K\\leq 16
  • KleqNleq200K \\leq N\\leq 200
  • AiA_i is 11, 22, ldots\\ldots, or KK.
  • AA contains at least one occurrence of each of 1,2,ldots,K1, 2, \\ldots, K.

Input

Input is given from Standard Input in the following format:

NN KK A1A_1 A2A_2 ldots\\ldots ANA_N

Output

Print the minimum number of operations needed to make AA satisfy the condition.


Sample Input 1

4 3
3 1 2 1

Sample Output 1

2

One optimal sequence of operations is as follows.

  • Swap A1A_1 and A2A_2, changing AA to (1,3,2,1)(1,3,2,1).
  • Swap A2A_2 and A3A_3, changing AA to (1,2,3,1)(1,2,3,1).
  • Now we have A1=1A_1 = 1, A2=2A_2 = 2, A3=3A_3 = 3, satisfying the condition.

Sample Input 2

5 5
4 1 5 2 3

Sample Output 2

5

Sample Input 3

8 4
4 2 3 2 4 2 1 4

Sample Output 3

5