import java.util.Scanner;

public class Main {

		/**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		}
		
		/**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		}
		/**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			}
}

 import java.util.Scanner; Scanner java.util public class Main {

		/**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		}
		
		/**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		}
		/**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			}
} Main /**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		} main {
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int num = scan.nextInt(); num scan.nextInt() scan.nextInt scan int[] value = new int[num]; value new int[num] num for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
				value[i] = scan.nextInt();
			} {
				value[i] = scan.nextInt();
			} value[i] = scan.nextInt() value[i] value i scan.nextInt() scan.nextInt scan System.out.println(ExchangeMax(value)) System.out.println System.out System System.out ExchangeMax(value) ExchangeMax value scan.close() scan.close scan String args[] args /**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		} ExchangeMax {
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		} int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = value[0]; min value[0] value 0 for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			} int i = 1; int i = 1; i 1 i < value.length i value.length value value.length i++ i++ i {
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			} {
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			} max = Math.max(max, value[i] - min) max Math.max(max, value[i] - min) Math.max Math max value[i] - min value[i] value i min min = Math.min(min, value[i]) min Math.min(min, value[i]) Math.min Math min value[i] value i return max; max int[] value value /**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			} Exchange {
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			} long max_sell = -999999999; max_sell -999999999 999999999 for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			} int i = n; int i = n; i n i < value.length i value.length value value.length i++ i++ i {
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			} {
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			} if(max_sell < value[i]){
					max_sell = value[i];
				} max_sell < value[i] max_sell value[i] value i {
					max_sell = value[i];
				} max_sell = value[i] max_sell value[i] value i return max_sell - buy; max_sell - buy max_sell buy int buy buy int[] value value int n n public class Main {

		/**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		}
		
		/**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		}
		/**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			}
} public class Main {

		/**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		}
		
		/**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		}
		/**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			}
} Main
import java.util.Scanner;

public class Main {

		/**
		 * それぞれの購入地点から得られる最大利ざやを求め、
		 * 最も利益の大きい値を出力する
		 * @param args
		 */
		public static void main(String args[]){
			Scanner scan = new Scanner(System.in);
			int num = scan.nextInt();
			int[] value = new int[num];
			for(int i = 0;i < num;i++){
				value[i] = scan.nextInt();
			}

		
			
			System.out.println(ExchangeMax(value));
			
			scan.close();
				
		/*	long profit = -999999999;
			for(int i = 0; i< num; i++){
				if(profit < Exchange(value[i],value,i+1)){
					profit = Exchange(value[i],value,i+1);
				}
			}
			System.out.println(profit);
			*/
		}
		
		/**
		 * 
		 */
		static int ExchangeMax(int[] value){
			int max = Integer.MIN_VALUE;
			int min = value[0];
			for(int i = 1; i < value.length;i++){
				max = Math.max(max, value[i] - min);
				min = Math.min(min, value[i]);
			}
			return max;
		}
		/**
		 * 購入地点からの最大利ざやを求める
		 * @param buy		買値
		 * @param value	価格変動値
		 * @param n		何番目から売りに入るか
		 * @return
		 */
		static long Exchange(int buy, int[] value,int n){
			long max_sell = -999999999;
			for(int i = n; i < value.length;i++){
				if(max_sell < value[i]){
					max_sell = value[i];
				}
			}
			return max_sell - buy;
			}
}


