package yukicoder; import java.util.Arrays; import java.util.Scanner; public class Main{ public static void main(String[] args)throws Exception{ new Main().solve(); } void solve(){ Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int k=sc.nextInt(); long[] a=new long[n]; for(int i=0;ia[i+j*k]){ m=i+j*k; min=a[i+j*k]; } } for(int j=0;m-(j+1)*k>=i;j++){ long d=a[m-j*k]; a[m-j*k]=a[m-(j+1)*k]; a[m-(j+1)*k]=d; count++; } } for(int i=0;i+1a[i+1]){ System.out.println(-1); return; } } System.out.println(count); } void tr(Object...o){System.out.println(Arrays.deepToString(o));} }