#include<stdio.h>

int main(void){
    int N, sum = 0;
    scanf("%d",&N);
    int A[N];
    for(int i = 0; i < N; i++){
        scanf("%d",&A[i]);
    }
    for(int i = 1; i < N; i++){
        int j = 0;
        while(A[i] < A[i-1]){
            sum++;
            A[i]++;
        }
    }
    printf("%d\n",sum);
    re