import numpy as  np

N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
maximum = max(A)

if len(set(A)) == 1:
    print(0)
else:
    max_point = int(np.where(A == maximum)[0])
    ans = [A[0]]
    for i in range(1, max_point):
        ans.append(A[0])


    for j in range(max_point+1):
        ans.append(maximum)

    print(sum(ans) - sum(A))