import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    }
} 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 min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int min; min int d; d min = scan.nextInt() min scan.nextInt() scan.nextInt scan int tmp = scan.nextInt(); tmp scan.nextInt() scan.nextInt scan d = tmp - min d tmp - min tmp min if(tmp < min){
    		min = tmp;
    	} tmp < min tmp min {
    		min = tmp;
    	} min = tmp min tmp for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        } int i = 1; int i = 1; i 1 i < n-1 i n-1 n 1 i++ i++ i {
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        } {
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        } int x = scan.nextInt(); x scan.nextInt() scan.nextInt scan if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            } x < min x min {
                min = x;
            } min = x min x {
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            } tmp = x - min tmp x - min x min if(d < tmp){
            		d = tmp;
            	} d < tmp d tmp {
            		d = tmp;
            	} d = tmp d tmp System.out.println(d) System.out.println System.out System System.out d String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    }
} 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 min;
        int d;
        min = scan.nextInt();
    	int tmp = scan.nextInt();
    	d = tmp - min;
    	if(tmp < min){
    		min = tmp;
    	}
        //max = min;
        for(int i = 1; i < n-1; i++){
            int x = scan.nextInt();
            if(x < min){
                min = x;
            }else{
            	tmp = x - min;
            	if(d < tmp){
            		d = tmp;
            	}
            }
        }
        System.out.println(d);
    }
}
