In what concerns the continuous evaluation solving exercises grade during the semester, you should submit until 23:59 of November 2nd
(this exercise will still be available for submission after that deadline, but without couting towards your grade)
[to understand the context of this problem, you should read the class #04 exercise sheet]


[AED017] Chocolate Boxes

John has N chocolate boxes available, each one with a certain amount of chocolates Ci. He wants to give one chocolate box to each of his friends, but since he wants to be as fair as possible he wants to choose which boxes to give in a way such that it minimizes the difference between the lowest and the highest number of chocolates a friend receives.

Can you help John discover how to do this and what is the smallest possible difference?

The Problem

Given a set of N chocolate boxes, the amount of chocolates Ci on each one and a number K of friends, your task is to compute the smallest possible difference between the lowest and the highest number of chocolates a friend receives if John gives exactly one box of chocolate to each of his K friends.

Input

The first input line contains two integers N (the amount of chocolate boxes) and K (the amount of friends).

The second line contains N space separated integers indicating the amount of chocolates in each box.

Output

The output should be a single line containing the smallest possible difference as previously described.

Constraints

The following limits are guaranteed in all the test cases that will be given to your program:

2 ≤ KN ≤ 105       Amount of friends and chocolate boxes
1 ≤ Ci ≤ 106       Amount of chocolates in one box

Example Input Example Output
8 5
7 5 1 4 4 6 5 9
2

John could give the following boxes: {4,4,5,5,6} (with a difference of 6-4 = 2)


Algorithms and Data Structures (L.EIC011) 2024/2025
DCC/FCUP & DEI/FEUP - University of Porto