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

ans=0

max=max(A)

for i in range(len(A)):
  if A[i] == max:
    a=i
    break

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

#print("tmp",tmp,"a",a,"A[a]",A[a])
  
total=0
for i in range(a):
  total += tmp - A[i]
  #print("total",total)
  
for i in range(a,len(A)):
  total += max - A[i]
  #print("total",total)

print(total)
