import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	}
} Main public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	} main {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) long n = scan.nextLong(); n scan.nextLong() scan.nextLong scan long max = scan.nextLong(); max scan.nextLong() scan.nextLong scan long sum = 0; sum 0 for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		} long i = 0; long i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		} {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		} long a = scan.nextLong(); a scan.nextLong() scan.nextLong scan if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			} a < max a max {
				sum += max - a;
			} sum += max - a sum max - a max a if(max < a){
				max = a;
			} max < a max a {
				max = a;
			} max = a max a System.out.print(sum) System.out.print System.out System System.out sum String args[] args public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	}
} public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	}
} Main
import java.util.Scanner;


public class Main {
	public static void main (String args[]) throws Exception{
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		long max = scan.nextLong();
		long sum = 0;
		
		for(long i = 0; i < n - 1 ; i++) {
			long a = scan.nextLong();
			if(a < max) {
				sum += max - a;
			} else if(max < a){
				max = a;
			}
		}
		
		System.out.print(sum);
	}
}