n = int(input())
a = list(map(int,input().split()))
MAX = max(a)
ans = 0
maxflg = False
minflg = False
for i in range(n):
    if a[i] == MAX:
        maxflg = True
        if i == 0:
            index = i + 1
        leftMAX = max(a[:index])
    if maxflg:
        ans += MAX - a[i]

for i in range(n):
    if a[i] == MAX:
        break
    else:
        ans += leftMAX - a[i] 
print(ans)