# Aをソートして二分探索 N, K = map(int, input().split()) A = list(map(int, input().split())) A.sort() def check(x): last = A[0] count = 1 s = 0 for i in range(N): if A[i] > last + x: s += A[i-1]-last last = A[i] count += 1 s += A[N-1]-last return count, s #for x in range(25): # print(x, check(x)) #print() OK1 = 10**12+1 NG1 = -1 while (OK1-NG1)>1: mid = (OK1+NG1)//2 if check(mid)[0] <= K: OK1 = mid else: NG1 = mid #print(OK1) OK2 = 10**12+1 NG2 = -1 while (OK2-NG2)>1: mid = (OK2+NG2)//2 if check(mid)[0] <= K-1: OK2 = mid else: NG2 = mid #print(OK2) ans = 10**12 for i in range(OK1, OK2+1): ans = min(ans, check(i)[1]) print(ans)