import math a=int(input()) b=int(input()) c=[int(input()) for i in range(a)] c.sort() if a//b>=2: print(math.ceil(max(c)-min(c)))