import itertools

import math

import fractions

import functools

import copy



n, k = list(map(int, input().split()))

h = []

for i in range(n):

    h.append(int(eval(input())))



h.sort()

minimum = 10**10

for i in range(n-k+1):

    minimum = min(minimum,h[i+k-1]-h[i])



print(minimum)
def main():

    # n = int(input())

    n, m = list(map(int, input().split()))

    # v = list(map(int, input().split()))

    # s = input()

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



    h.sort()



    temp = []

    for i in range(n-m+1):

        temp.append(h[i+m-1]-h[i])



    temp.sort()

    print((temp[0]))





if __name__ == '__main__':

    main()

import itertools
import math
import fractions
import functools
import copy

n, k = list(map(int, input().split()))
h = []
for i in range(n):
    h.append(int(eval(input())))
h.sort()
minimum = 10**10
for i in range(n - k + 1):
    minimum = min(minimum, h[i + k - 1] - h[i])
print(minimum)

def main():
    # n = int(input())
    n, m = list(map(int, input().split()))
    # v = list(map(int, input().split()))
    # s = input()
    h = [int(eval(input())) for _ in range(n)]
    h.sort()
    temp = []
    for i in range(n - m + 1):
        temp.append(h[i + m - 1] - h[i])
    temp.sort()
    print((temp[0]))


if __name__ == "__main__":
    main()

-import itertools -import math -import fractions -import functools -import copy +def main(): +    # n = int(input()) +    n, m = list(map(int, input().split())) +    # v = list(map(int, input().split())) +    # s = input() +    h = [int(eval(input())) for _ in range(n)] +    h.sort() +    temp = [] +    for i in range(n - m + 1): +        temp.append(h[i + m - 1] - h[i]) +    temp.sort() +    print((temp[0])) -n, k = list(map(int, input().split())) -h = [] -for i in range(n): -    h.append(int(eval(input()))) -h.sort() -minimum = 10**10 -for i in range(n - k + 1): -    minimum = min(minimum, h[i + k - 1] - h[i]) -print(minimum) + +if __name__ == "__main__": +    main()