{"raw_statement":[{"iden":"problem statement","content":"Given is a sequence of $N$ positive integers $A = (A_1, A_2, \\ldots, A_N)$, where each $A_i$ is $1$, $2$, $\\ldots$, or $K$.\nYou can do the following operation on this sequence any number of times.\n\n*   Swap two adjacent elements, that is, choose $i$ and $j$ such that $|i-j|=1$ and swap $A_i$ and $A_j$.\n\nFind the minimum number of operations needed to make $A$ satisfy the following condition.\n\n*   $A$ contains $(1, 2, \\ldots, K)$ as a contiguous subsequence, that is, there is a positive integer $n$ at most $N-K+1$ such that $A_n = 1$, $A_{n+1} = 2$, $\\ldots$, and $A_{n+K-1} = K$."},{"iden":"constraints","content":"*   $2\\leq K\\leq 16$\n*   $K \\leq N\\leq 200$\n*   $A_i$ is $1$, $2$, $\\ldots$, or $K$.\n*   $A$ contains at least one occurrence of each of $1, 2, \\ldots, K$."},{"iden":"input","content":"Input is given from Standard Input in the following format:\n\n$N$ $K$\n$A_1$ $A_2$ $\\ldots$ $A_N$"},{"iden":"sample input 1","content":"4 3\n3 1 2 1"},{"iden":"sample output 1","content":"2\n\nOne optimal sequence of operations is as follows.\n\n*   Swap $A_1$ and $A_2$, changing $A$ to $(1,3,2,1)$.\n*   Swap $A_2$ and $A_3$, changing $A$ to $(1,2,3,1)$.\n*   Now we have $A_1 = 1$, $A_2 = 2$, $A_3 = 3$, satisfying the condition."},{"iden":"sample input 2","content":"5 5\n4 1 5 2 3"},{"iden":"sample output 2","content":"5"},{"iden":"sample input 3","content":"8 4\n4 2 3 2 4 2 1 4"},{"iden":"sample output 3","content":"5"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}