n = int(input())
list = list(map(int,input().split()))

ans = 0
maxV = max(list)
for i,ele in enumerate(list):
    if i == len(list)-1:
        continue

    if ele == maxV:
        for j in range(i+1,len(list)-1):
            # print(i, "maxV")
            hoge = maxV-list[j]
            # print(hoge)
            ans += hoge
            break

    if ele > list[i+1]:
        # print(i, "minus")
        hoge = ele - list[i+1]
        ans += hoge

print(ans)
