N = int(input()) K = int(input()) n = [input().rstrip() for i in range(N)] n = [int(i) for i in n] print(max(n) - min(n))