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

h = [None] * N

for i in range(N):

    h[i] = int(eval(input()))



h = sorted(h)



sub_min = h[N-1] - h[0]

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

    if h[i+K-1] - h[i] < sub_min:

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



print(sub_min)
# coding: utf-8



# https://atcoder.jp/contests/abc115





def main():

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

    h = [None] * N

    for i in range(N):

        h[i] = int(eval(input()))



    h = sorted(h)



    diff = 10**10

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

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

        if newdiff < diff:

            diff = newdiff



    return diff





print((main()))

N, K = list(map(int, input().split()))
h = [None] * N
for i in range(N):
    h[i] = int(eval(input()))
h = sorted(h)
sub_min = h[N - 1] - h[0]
for i in range(N - K + 1):
    if h[i + K - 1] - h[i] < sub_min:
        sub_min = h[i + K - 1] - h[i]
print(sub_min)

# coding: utf-8
# https://atcoder.jp/contests/abc115
def main():
    N, K = list(map(int, input().split()))
    h = [None] * N
    for i in range(N):
        h[i] = int(eval(input()))
    h = sorted(h)
    diff = 10**10
    for i in range(N - K + 1):
        newdiff = h[i + K - 1] - h[i]
        if newdiff < diff:
            diff = newdiff
    return diff


print((main()))

-N, K = list(map(int, input().split())) -h = [None] * N -for i in range(N): -    h[i] = int(eval(input())) -h = sorted(h) -sub_min = h[N - 1] - h[0] -for i in range(N - K + 1): -    if h[i + K - 1] - h[i] < sub_min: -        sub_min = h[i + K - 1] - h[i] -print(sub_min) +# coding: utf-8 +# https://atcoder.jp/contests/abc115 +def main(): +    N, K = list(map(int, input().split())) +    h = [None] * N +    for i in range(N): +        h[i] = int(eval(input())) +    h = sorted(h) +    diff = 10**10 +    for i in range(N - K + 1): +        newdiff = h[i + K - 1] - h[i] +        if newdiff < diff: +            diff = newdiff +    return diff + + +print((main()))