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

H=[]

count=10**9

for i in range(N):

   h=int(eval(input()))

   H.append(h)

H.sort()



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

   hmax_min=H[i+K-1]-H[i]

   count=min(count,hmax_min)



print(count)
def main():

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

    h=[]

    for i in range(N):

        a=int(eval(input()))

        h.append(a)

    

    h.sort()

    result=10**10

    count=0

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

        count=h[i+K-1]-h[i]

        result=min(result,count)

    print(result)

if __name__=="__main__":

    main()
N, K = list(map(int, input().split()))
H = []
count = 10**9
for i in range(N):
    h = int(eval(input()))
    H.append(h)
H.sort()
for i in range(0, N - K + 1):
    hmax_min = H[i + K - 1] - H[i]
    count = min(count, hmax_min)
print(count)

def main():
    N, K = list(map(int, input().split()))
    h = []
    for i in range(N):
        a = int(eval(input()))
        h.append(a)
    h.sort()
    result = 10**10
    count = 0
    for i in range(N - K + 1):
        count = h[i + K - 1] - h[i]
        result = min(result, count)
    print(result)


if __name__ == "__main__":
    main()

-N, K = list(map(int, input().split())) -H = [] -count = 10**9 -for i in range(N): -    h = int(eval(input())) -    H.append(h) -H.sort() -for i in range(0, N - K + 1): -    hmax_min = H[i + K - 1] - H[i] -    count = min(count, hmax_min) -print(count) +def main(): +    N, K = list(map(int, input().split())) +    h = [] +    for i in range(N): +        a = int(eval(input())) +        h.append(a) +    h.sort() +    result = 10**10 +    count = 0 +    for i in range(N - K + 1): +        count = h[i + K - 1] - h[i] +        result = min(result, count) +    print(result) + + +if __name__ == "__main__": +    main()