import numpy as np

from numba import jit

N = int(eval(input('')))

A1 = np.array(list(map(int, input('').split(' '))))



@jit(nopython=True)

def func(A):

    step = 0

    for k in range(0,N-1):

        if A[k] > A[k+1]:

            add = A[k] - A[k+1]

            step += add

            A[k+1] += add

    return step

        

print((func(A1)))
import numpy as np

N = int(eval(input('')))

A1 = np.array(list(map(int, input('').split(' '))))



def func(A):

    step = 0

    for k in range(0,N-1):

        if A[k] > A[k+1]:

            add = A[k] - A[k+1]

            step += add

            A[k+1] += add

    return step

        

print((func(A1)))
import numpy as np
from numba import jit

N = int(eval(input("")))
A1 = np.array(list(map(int, input("").split(" "))))


@jit(nopython=True)
def func(A):
    step = 0
    for k in range(0, N - 1):
        if A[k] > A[k + 1]:
            add = A[k] - A[k + 1]
            step += add
            A[k + 1] += add
    return step


print((func(A1)))

import numpy as np

N = int(eval(input("")))
A1 = np.array(list(map(int, input("").split(" "))))


def func(A):
    step = 0
    for k in range(0, N - 1):
        if A[k] > A[k + 1]:
            add = A[k] - A[k + 1]
            step += add
            A[k + 1] += add
    return step


print((func(A1)))

-from numba import jit -@jit(nopython=True)