def resolve():

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

    l=[int(eval(input())) for i in range(n)]

    l.sort()

    print((min(l[i+k-1]-l[i] for i in range(n-k+1))))

resolve()
import sys

def input(): return sys.stdin.readline().strip()



def resolve():

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

    l=[int(eval(input())) for i in range(n)]

    l.sort()

    ans=10**18

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

        ans=min(ans,l[i+k-1]-l[i])

    print(ans)

resolve()
def resolve():
    n, k = list(map(int, input().split()))
    l = [int(eval(input())) for i in range(n)]
    l.sort()
    print((min(l[i + k - 1] - l[i] for i in range(n - k + 1))))


resolve()

import sys


def input():
    return sys.stdin.readline().strip()


def resolve():
    n, k = list(map(int, input().split()))
    l = [int(eval(input())) for i in range(n)]
    l.sort()
    ans = 10**18
    for i in range(0, n - k + 1):
        ans = min(ans, l[i + k - 1] - l[i])
    print(ans)


resolve()

+import sys + + +def input(): +    return sys.stdin.readline().strip() + + -    print((min(l[i + k - 1] - l[i] for i in range(n - k + 1)))) +    ans = 10**18 +    for i in range(0, n - k + 1): +        ans = min(ans, l[i + k - 1] - l[i]) +    print(ans)