n, m = map(int, input().split()) a = sorted([*map(int, input().split())]) d = [(v - u) ** 2 for u, v in zip(a, a[1:])] for i in range(1, n - 1): d[i] += d[i - 1] d = [0] + d ans = 10 ** 50 for i in range(n - m): ans = min(ans, d[i + m - 1] - d[i]) print(ans)