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,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	}
} 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,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	}
} Main public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int min,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	} main {
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int min,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int N=scan.nextInt(); N scan.nextInt() scan.nextInt scan int min min t t ans; ans min=scan.nextInt() min scan.nextInt() scan.nextInt scan t=scan.nextInt() t scan.nextInt() scan.nextInt scan ans=t-min ans t-min t min if(t<min) min=t; t<min t min min=t min t for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		} int i=0; int i=0; i 0 i<N-2 i N-2 N 2 i++ i++ i {
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		} {
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		} t=scan.nextInt() t scan.nextInt() scan.nextInt scan if(ans<t-min){
				ans=t-min;
			} ans<t-min ans t-min t min {
				ans=t-min;
			} ans=t-min ans t-min t min if(t<min){
				min=t;
			} t<min t min {
				min=t;
			} min=t min t System.out.println(ans) System.out.println System.out System System.out ans scan.close() scan.close scan String[] args args public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int min,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	}
} public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int N=scan.nextInt();
		int min,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	}
} 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,t,ans;//minはその時間までの最安値
		min=scan.nextInt();
		t=scan.nextInt();
		ans=t-min;
		if(t<min) min=t;
		for(int i=0;i<N-2;i++){
			t=scan.nextInt();
			if(ans<t-min){
				ans=t-min;
			}
			if(t<min){
				min=t;
			}
		}
		System.out.println(ans);
		scan.close();
	}
}