n = input()
m = input().split()
m = [int(i) for i in m]

mx = max(m)
ind = m.index(mx)

c = 0
j = len(m)
for i in reversed(m[ind:]):
    if i < mx:
        d = mx - i
        c += d
ind_i = 0
for i in m[1:ind]:
    if m[ind_i] > i:
        num = m[ind_i] - i
        c+= num
    ind_i += 1
    
print(c)