N = int(input())
numbers = input().split()
numbers = list(map(int,numbers))
m = 0
gross_count = 0
for n in numbers:
    if m > n:
        gross_count += (m-n)
        print(gross_count)
    else:
        m = n
print(gross_count)