n = int(input())

a = list(map(int, input().split()))

highest = 0
last = 0
for i in range(n):
    if a[i] >= highest:
        highest = a[i]
        last = i

shortest = highest
for j in range(0, last):
    if a[j] <= shortest:
        shortest = a[j]
        #print(shortest)

print(highest - shortest)