import  java.util.*;
class Main{
    int n;
        
    Main(){
	Scanner sc = new Scanner(System.in);
	n=sc.nextInt();
	int ans=-1000000000;
	int mini;
	mini=sc.nextInt();

	for(int i=0; i<n-1; i++){
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	}
       
	System.out.println(ans);
    }

    int max(int a,int b){
	if(a>b)return a;
	else return b;
    }

    int min(int a,int b){
	if(a<b)return a;
	else return b;
    }





    public static void main(String[] args){
	new Main();
    }
} import  java.util.*; util.* java class Main{
    int n;
        
    Main(){
	Scanner sc = new Scanner(System.in);
	n=sc.nextInt();
	int ans=-1000000000;
	int mini;
	mini=sc.nextInt();

	for(int i=0; i<n-1; i++){
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	}
       
	System.out.println(ans);
    }

    int max(int a,int b){
	if(a>b)return a;
	else return b;
    }

    int min(int a,int b){
	if(a<b)return a;
	else return b;
    }





    public static void main(String[] args){
	new Main();
    }
} Main int n; n Main(){
	Scanner sc = new Scanner(System.in);
	n=sc.nextInt();
	int ans=-1000000000;
	int mini;
	mini=sc.nextInt();

	for(int i=0; i<n-1; i++){
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	}
       
	System.out.println(ans);
    } Main {
	Scanner sc = new Scanner(System.in);
	n=sc.nextInt();
	int ans=-1000000000;
	int mini;
	mini=sc.nextInt();

	for(int i=0; i<n-1; i++){
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	}
       
	System.out.println(ans);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n=sc.nextInt() n sc.nextInt() sc.nextInt sc int ans=-1000000000; ans -1000000000 1000000000 int mini; mini mini=sc.nextInt() mini sc.nextInt() sc.nextInt sc for(int i=0; i<n-1; i++){
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	} int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	} {
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	} int num=sc.nextInt(); num sc.nextInt() sc.nextInt sc ans=max(ans,num-mini) ans max(ans,num-mini) max ans num-mini num mini mini=min(mini,num) mini min(mini,num) min mini num System.out.println(ans) System.out.println System.out System System.out ans int max(int a,int b){
	if(a>b)return a;
	else return b;
    } max {
	if(a>b)return a;
	else return b;
    } if(a>b)return a;
	else return b; a>b a b return a; a return b; b int a a int b b int min(int a,int b){
	if(a<b)return a;
	else return b;
    } min {
	if(a<b)return a;
	else return b;
    } if(a<b)return a;
	else return b; a<b a b return a; a return b; b int a a int b b public static void main(String[] args){
	new Main();
    } main {
	new Main();
    } new Main() String[] args args
import  java.util.*;
class Main{
    int n;
        
    Main(){
	Scanner sc = new Scanner(System.in);
	n=sc.nextInt();
	int ans=-1000000000;
	int mini;
	mini=sc.nextInt();

	for(int i=0; i<n-1; i++){
	    int num=sc.nextInt();
	    
	    ans=max(ans,num-mini);

	    mini=min(mini,num);
	}
       
	System.out.println(ans);
    }

    int max(int a,int b){
	if(a>b)return a;
	else return b;
    }

    int min(int a,int b){
	if(a<b)return a;
	else return b;
    }





    public static void main(String[] args){
	new Main();
    }
}