import sys





def main() -> None:

    n, k = [int(s) for s in input().split()]

    h = []

    for i in range(n):

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

    h.sort()



    mn = sys.maxsize

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

        cnt = h[i + k - 1] - h[i]

        mn = min(mn, cnt)



    print(mn)





if __name__ == '__main__':

    main()
import sys



n, k = [int(s) for s in input().split()]

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



mn = sys.maxsize

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

    cnt = h[i + k - 1] - h[i]

    mn = min(mn, cnt)



print(mn)
import sys


def main() -> None:
    n, k = [int(s) for s in input().split()]
    h = []
    for i in range(n):
        h += [int(eval(input()))]
    h.sort()
    mn = sys.maxsize
    for i in range(n - k + 1):
        cnt = h[i + k - 1] - h[i]
        mn = min(mn, cnt)
    print(mn)


if __name__ == "__main__":
    main()

import sys

n, k = [int(s) for s in input().split()]
h = sorted([int(eval(input())) for _ in range(n)])
mn = sys.maxsize
for i in range(n - k + 1):
    cnt = h[i + k - 1] - h[i]
    mn = min(mn, cnt)
print(mn)

- -def main() -> None: -    n, k = [int(s) for s in input().split()] -    h = [] -    for i in range(n): -        h += [int(eval(input()))] -    h.sort() -    mn = sys.maxsize -    for i in range(n - k + 1): -        cnt = h[i + k - 1] - h[i] -        mn = min(mn, cnt) -    print(mn) - - -if __name__ == "__main__": -    main() +n, k = [int(s) for s in input().split()] +h = sorted([int(eval(input())) for _ in range(n)]) +mn = sys.maxsize +for i in range(n - k + 1): +    cnt = h[i + k - 1] - h[i] +    mn = min(mn, cnt) +print(mn)