ans = 10**10

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

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



for i in range(N-K+1):

    ans = min(ans, h[i+K-1] - h[i])

print(ans)
import sys



input = sys.stdin.readline



def main():

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

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

    

    ans = float('inf')

    

    for i in range(N-K+1):

        ans = min(ans, h[i+K-1] - h[i])

    

    print(ans)

    

if __name__ == '__main__':

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

import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

-ans = 10**10 -N, K = list(map(int, input().split())) -h = sorted([int(eval(input())) for i in range(N)]) -for i in range(N - K + 1): -    ans = min(ans, h[i + K - 1] - h[i]) -print(ans) +import sys + +input = sys.stdin.readline + + +def main(): +    N, K = list(map(int, input().split())) +    h = sorted([int(eval(input())) for i in range(N)]) +    ans = float("inf") +    for i in range(N - K + 1): +        ans = min(ans, h[i + K - 1] - h[i]) +    print(ans) + + +if __name__ == "__main__": +    main()