a = int(input())
b = input().split(" ")
i = 0
m = 0
d = [0] * a
while i < a :
    d[i] = int(b[i])
    i = i + 1
i = a - 1
while i > 0 :
    m = m + (max(d) - d[i])
    d.pop()
    i = i - 1
print(m)
