N=int(input())
A=[int(_) for _ in input().split(" ")]

max=max(A)
 
if A[0] == max:
  total=0
  for i in range(len(A)):
    total=total+max-A[i]
  print(total)
  exit()

ans=0
total=0
b=len(A)
a=1

while a!=0:
  max=0
  for i in range(b):
    if max < A[i]:
      a=i
      max=A[i]
  for i in range(a,b):
    total += max - A[i]
  b=a

print(total)
    
