import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	}
} import java.io.*; io.* java import java.util.*; util.* java public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	}
} Main public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	} main {
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	} Scanner cin= new Scanner(System.in); cin new Scanner(System.in) int N= cin.nextInt(); N cin.nextInt() cin.nextInt cin int min= (int)Math.pow(10d,9d); min (int)Math.pow(10d,9d) Math.pow Math 10d 9d int MaxProfit= -min; MaxProfit -min min int Rate; Rate int i; i for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		} i=0; i=0 i 0 i<N i N i++ i++ i {
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		} {
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		} Rate= cin.nextInt() Rate cin.nextInt() cin.nextInt cin if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			} i==0 i 0 {
				min= Rate;
			} min= Rate min Rate {
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			} if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				} Rate-min > MaxProfit Rate-min Rate min MaxProfit {
					MaxProfit= Rate-min;
				} MaxProfit= Rate-min MaxProfit Rate-min Rate min if( Rate<min ){
					min= Rate;
				} Rate<min Rate min {
					min= Rate;
				} min= Rate min Rate System.out.println(MaxProfit) System.out.println System.out System System.out MaxProfit String args[] args public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	}
} public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	}
} Main
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String args[]) throws Exception{
		Scanner cin= new Scanner(System.in);
		int N= cin.nextInt();
		
		int min= (int)Math.pow(10d,9d);
		int MaxProfit= -min;
		int Rate;
		
		int i;
		for(i=0;i<N;i++){
			Rate= cin.nextInt();
			if(i==0){
				min= Rate;
			}
			else{
				if( Rate-min > MaxProfit ){
					MaxProfit= Rate-min;
				}
				if( Rate<min ){
					min= Rate;
				}
			}
		}
		System.out.println(MaxProfit);
	}
}