n = int(input())
a = []
for i in range(n):
    a[i] = int(input())
    
b = []
for j in range(n-1):
    b[j] = a[j+1]

count = 0
for k in range(n-1):
    if b[k] - a[k] < 0:
        count = abs(b[k] - a[k])

print(count)