n = int(input()) k = int(input()) num = [int(input()) for i in range(n)] num.sort(reverse = True) print(num[0]-num[result])