import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
max_ind = np.argmax(A)
min_array = np.full(max_ind, A[0])
max_array = np.full(len(A)-max_ind, max(A))
bin_array = np.hstack((min_array, max_array))
hikizan = bin_array - A

y = np.where(hikizan < 0)
if y != 0:
    hikizan[y] = 0
print(np.sum(hikizan))