import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
public class Main {


    
    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
} import java.io.*; io.* java import java.math.*; math.* java import java.util.*; util.* java import java.lang.*; lang.* java public class Main {


    
    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
} Main public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    } main {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    } PrintWriter pw=new PrintWriter(System.out); pw new PrintWriter(System.out) FastScanner sc = new FastScanner(); sc new FastScanner() int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long[] a = new long[n]; a new long[n] n long ans=0; ans 0 long max=0; max 0 for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        } {
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        } a[i] = sc.nextLong() a[i] a i sc.nextLong() sc.nextLong sc max = (max<a[i])?a[i]:max max (max<a[i])?a[i]:max (max<a[i]) max a[i] a i a[i] a i max ans+=(max-a[i]) ans (max-a[i]) max a[i] a i pw.println(ans) pw.println pw ans pw.close() pw.close pw String args[] args public static <T> void deb(T x){
       System.out.println(x);
   } deb {
       System.out.println(x);
   } System.out.println(x) System.out.println System.out System System.out x T x x static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	} FastScanner BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringTokenizer st=new StringTokenizer(""); st new StringTokenizer("") public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		} next {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		} while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				} !st.hasMoreElements() st.hasMoreElements() st.hasMoreElements st try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				} catch (IOException e) {
					e.printStackTrace();
				} IOException e {
					e.printStackTrace();
				} e.printStackTrace() e.printStackTrace e {
					st=new StringTokenizer(br.readLine());
				} st=new StringTokenizer(br.readLine()) st new StringTokenizer(br.readLine()) return st.nextToken(); st.nextToken() st.nextToken st public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		} next {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		} try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} IOException e {
				e.printStackTrace();
			} e.printStackTrace() e.printStackTrace e {
				return br.readLine();
			} return br.readLine(); br.readLine() br.readLine br return "Not able to read"; "Not able to read" int k k int nextInt() {
			return Integer.parseInt(next());
		} nextInt {
			return Integer.parseInt(next());
		} return Integer.parseInt(next()); Integer.parseInt(next()) Integer.parseInt Integer next() next long nextLong() {
			return Long.parseLong(next());
		} nextLong {
			return Long.parseLong(next());
		} return Long.parseLong(next()); Long.parseLong(next()) Long.parseLong Long next() next double nextDouble() {
			return Double.parseDouble(next());
		} nextDouble {
			return Double.parseDouble(next());
		} return Double.parseDouble(next()); Double.parseDouble(next()) Double.parseDouble Double next() next public class Main {


    
    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
} public class Main {


    
    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
} Main
import java.io.*;
import java.math.*;
import java.util.*;
import java.lang.*;

// import java.text.DecimalFormat; 
// import java.text.DecimalFormatSymbols; 
 
public class Main {


    
    public static void main(String args[] ) throws Exception {
        PrintWriter pw=new PrintWriter(System.out);
        FastScanner sc = new FastScanner();
        int n = sc.nextInt();
        long[] a = new long[n];
        long ans=0;
        long max=0;
        for(int i=0;i<n;i++){
            a[i] = sc.nextLong();
            max = (max<a[i])?a[i]:max;
            ans+=(max-a[i]);
        }
        
       pw.println(ans);
        
        pw.close();
    }
    
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   public static <T> void deb(T x){
       System.out.println(x);
   }
   
   
   static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		
		public String next() {
			while (!st.hasMoreElements())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		public String next(int k) {
			try {
				return br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return "Not able to read";
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		
		long nextLong() {
			return Long.parseLong(next());
		}
		
		double nextDouble() {
			return Double.parseDouble(next());
		}
		
	    
	}
   
}