N = int(input())
height = list(map(int, input().split()))
total = 0
max_number = height[0]

for i in range(1, height.index(max(height))):
	if height[i] > max_number:
		max_number = height[i]
	else:
		total += (max_number - height[i])

for i in range(height.index(max(height)), N):
	total += (max(height)-height[i])
    
print(total)