n = int(input())
a = list(map(int, input().split()))

amax = max(a)
x = a.index(amax)
if x > 0:
   bmax = max(a[:x])
else:
   bmax = 0

ans = 0
for i in range(n):
   if i < x:
      ans += max(0, bmax-a[i])
   else:
      ans += max(0, amax-a[i])
print(ans)
