#robot N,K=(int(i) for i in input().split()) a=[int(i) for i in input().split()] b=[0]*N for i in range(N): b[i]=a[i] b.sort() i=0 C=0 while i=0: j=i while j=0 and b[j]!=a[i]: j=i while j=0 and b[j]!=a[i]: j+=K # print(C) if j>=N: C=-1 else: l=0 while i+l+K<=j: t=a[i+l] a[i+l]=a[i+l+K] a[i+l+K]=t l+=K C+=1 # print(a) i+=1 # print(a) print(C)