n = int(input())
A = list(map(int,input().split()))

step = 0
ma = max(A)
idx = A.index(ma)
for i in range(idx-1):
    dif = A[i+1]-A[i]
    if dif < 0:
        step += abs(dif)
for i in range(idx,n):
    dif = ma-A[i]
    step += dif
print(step)