import java.util.Scanner; public class Main { public static void main(String[] args) { try (Scanner scan = new Scanner(System.in)) { int n = scan.nextInt(); int k = scan.nextInt(); int list[] = new int[n]; for(int i=0; i 0) { for(int g=0; g list[p+k]) { int w = list[p]; list[p] = list[p+k]; list[p+k] = w; ans++; } } } m -= k; } boolean flag = true; for(int i=0; i list[i+1]) { flag = false; break; } } System.out.println(flag? ans : -1); } } }