N, M = map(int, input().split())
arr = list(map(int, input().split()))

# Algo
arr.sort()
minL = min(arr[i]**2-arr[i-M+1]**2 for i in range(M-1, N))

# Output
print(minL)