
Imports System.Console
Module Module1
    Dim ans As Int64
    Dim max As Int64
    Dim n, k, x, t As Int64
    Sub Main()
        Dim s() As String = ReadLine.Split
        n = s(0)
        s = ReadLine.Split
        Dim a(s.Length - 1) As Integer
        For i = 0 To s.Length - 1
            a(i) = s(i)
        Next
        max = a(0)
        For i = 1 To n - 1
            If a(i) <= max Then
                ans += (max - a(i))
            Else
                max = a(i)
            End If
        Next
        WriteLine(ans)
    End Sub
End Module
