# coding=utf-8

if __name__ == '__main__':
    N = int(input())

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

    M = max(li)
    # print(M)

    MV = li[0]
    C = 0
    hai = li.index(M)
    #print(hai)
    for i in range(N):
        if i < hai:
            if MV > li[i]:
                C += MV - li[i]

        else:
            C += M - li[i]
        #print(C)

    print(C)
