#include <iostream>
using namespace std;

int N, K;
int A[200000];
int min, cnt;

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> A[i];

    min = A[0];
    cnt = 0;

    for (int i = 0; i < N; ++i) {
        if (min < A[i]) {
            min = A[i];
        }
        cnt = cnt + min - A[i];
    }

    cout << cnt;

}