Sorting Game
Very easy
Execution time limit is 1 second
Runtime memory usage limit is 128 megabytes
In The Sorting Game, you are given a sequence containing a permutation of the integers between 1 and n, inclusive. In one move, you can take any k consecutive elements of the sequence and reverse their order. Find the fewest number of moves to sort the sequence in ascending order.
Input
Consists of multiple test cases. The first line of each test case contains two integers n (2 ≤ n ≤ 8) and k (2 ≤ k ≤ n). The second line of each test case contains a permutation of numbers from 1 to n.
Output
For each test case print in a separate line the fewest number of moves to sort the sequence in ascending order or -1 if it's impossible.
Examples
Input #1
Answer #1
Submissions 566
Acceptance rate 45%