import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	} main {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int A[] = new int[N]; A new int[N] N long step = 0; step 0 int max = 0; max 0 for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			A[i] = scan.nextInt();
		} {
			A[i] = scan.nextInt();
		} A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan max = A[0] max A[0] A 0 for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		} {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		} if(max <= A[i]) {
				max = A[i];
			} max <= A[i] max A[i] A i {
				max = A[i];
			} max = A[i] max A[i] A i step += max - A[i] step max - A[i] max A[i] A i System.out.println(step) System.out.println System.out System System.out step String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	}
} Main
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);

		int N = scan.nextInt();
		int A[] = new int[N];
		long step = 0;
		int max = 0;
		for(int i=0; i<N; i++) {
			A[i] = scan.nextInt();
		}

		max = A[0];
		for(int i=0; i<N; i++) {
			if(max <= A[i]) {
				max = A[i];
			}
			step += max - A[i];
		}
		System.out.println(step);
	}
}
