def main():

    N, K = list(map(int, input().split()))

    h = [int(eval(input())) for _ in range(N)]

    h.sort()

    print((min([h[i + K - 1] - h[i] for i in range(N - K + 1)])))

        

    

if __name__ == '__main__':

    main()
N, K, *h = list(map(int, open(0).read().split()))

h.sort()

ans = [h[i + K - 1] - h[i] for i in range(N - K + 1)]

print((min(ans)))
def main():
    N, K = list(map(int, input().split()))
    h = [int(eval(input())) for _ in range(N)]
    h.sort()
    print((min([h[i + K - 1] - h[i] for i in range(N - K + 1)])))


if __name__ == "__main__":
    main()

N, K, *h = list(map(int, open(0).read().split()))
h.sort()
ans = [h[i + K - 1] - h[i] for i in range(N - K + 1)]
print((min(ans)))

-def main(): -    N, K = list(map(int, input().split())) -    h = [int(eval(input())) for _ in range(N)] -    h.sort() -    print((min([h[i + K - 1] - h[i] for i in range(N - K + 1)]))) - - -if __name__ == "__main__": -    main() +N, K, *h = list(map(int, open(0).read().split())) +h.sort() +ans = [h[i + K - 1] - h[i] for i in range(N - K + 1)] +print((min(ans)))