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
v = max(d)
while i > 0 :
    k = 0
    m = m + (v - d[i])
    if d[i] == max(d) :
        k = k + 1
    d.pop()
    if k == 1 :
        v = max(d)
    i = i - 1
print(m)
