# -*- coding: utf-8 -*- import sys,copy,math,heapq,itertools as it,fractions,re,bisect,collections as coll N, K = map(int, raw_input().split()) a = map(int, raw_input().split()) i = ans = 0 while i < N - K: if a[i] > a[i + K]: a[i], a[i + K] = a[i + K], a[i] ans += 1 i = 0 else: i += 1 if min(a[i + 1] - a[i] for i in xrange(N - 1)) >= 1: print ans else: print -1