n=int(input())
lst=list(map(int,input().split()))
lst1=[]
for i in range(n):
	if lst[i+1]<lst[i]:
    	count=lst[i]-lst[i+1]
        lst1.append(count)
        lst[i+1]=lst[i+1]+count
	else:
      	x=0
sum=0
for i in lst1:
	sum+=i
    print(sum)