N = input()
hight = input()
arr = [int(i) for i in hight.split()]
newArr = [int(i) for i in hight.split()]
sum = 0
index = newArr.index(max(newArr))
for i in range(index,len(newArr)):
    newArr[i] = max(newArr)
for i in range(0,index):
    newArr[i] = max([newArr[j] for j in range(0,index)])
for i in range(len(arr)):
    sum+=newArr[i]-arr[i]

print(sum)