import heapq import math n = int(input()) k = int(input()) ni = [int(input()) for i in range(n)] h = [] m = [] for i in ni: heapq.heappush(h, -i) for i in ni: heapq.heappush(m, i) nmax = heapq.heappop(h) nmin = heapq.heappop(m) print(math.ceil(-nmax - nmin))