import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		int n = scan.nextInt();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	}
} 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();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		int n = scan.nextInt();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	} main {
		Scanner scan = new Scanner(System.in);		int n = scan.nextInt();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan long[] data = new long[n]; data new long[n] n long max = 0; max 0 for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		} int i = 0 ; int i = 0 ; i 0 i < n i n i++ i++ i {
			data[i]=scan.nextLong();
		} {
			data[i]=scan.nextLong();
		} data[i]=scan.nextLong() data[i] data i scan.nextLong() scan.nextLong scan long min = Long.MAX_VALUE; min Long.MAX_VALUE Long Long.MAX_VALUE max=data[n-1]-data[0] max data[n-1]-data[0] data[n-1] data n-1 n 1 data[0] data 0 for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		} int i = 0 ; int i = 0 ; i 0 i < n i n i ++ i ++ i {
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		} {
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		} if (data[i]>min) {
                continue;
            } data[i]>min data[i] data i min {
                continue;
            } continue; min=data[i] min data[i] data i for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			} int j = n-1 ; int j = n-1 ; j n-1 n 1 j > i j i j -- j -- j {
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			} {
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			} if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				} max<(data[j]-data[i]) max (data[j]-data[i]) data[j] data j data[i] data i {
					max= data[j]-data[i];
				} max= data[j]-data[i] max data[j]-data[i] data[j] data j data[i] data i System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		int n = scan.nextInt();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	}
} public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		int n = scan.nextInt();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);		int n = scan.nextInt();
		long[] data = new long[n];
		long max = 0;
		for(int i = 0 ; i < n ; i++){
			data[i]=scan.nextLong();
		}
		long min = Long.MAX_VALUE;
		max=data[n-1]-data[0];
		for(int i = 0 ; i < n ; i ++){
			if (data[i]>min) {
                continue;
            }
			min=data[i];
			for(int j = n-1 ; j > i ; j --){
				if(max<(data[j]-data[i])){
					max= data[j]-data[i];
				}
				//System.out.println(data[i]-data[j]);
			}
		}
		System.out.println(max);
	}
}