import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	}
	
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
} import java.util.*; util.* java public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	}
	
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	} main {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	} int m = sc.nextInt(); m sc.nextInt() sc.nextInt sc int[] R = new int[m]; R new int[m] m for(int i=0;i<m;i++) R[i] = sc.nextInt(); int i=0; int i=0; i 0 i<m i m i++ i++ i R[i] = sc.nextInt(); R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc int mn = R[0]; mn R[0] R 0 int ret = -1000000001; ret -1000000001 1000000001 for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		} int i=1; int i=1; i 1 i<m i m i++ i++ i {
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		} {
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		} ret = Math.max(ret, R[i]-mn) ret Math.max(ret, R[i]-mn) Math.max Math ret R[i]-mn R[i] R i mn mn = Math.min(mn, R[i]) mn Math.min(mn, R[i]) Math.min Math mn R[i] R i cout(ret) cout ret String[] args args public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	} isPrime {
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	} for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		} int i=2; int i=2; i 2 i<=n*n i n*n n n i++ i++ i {
			if(n%i==0) return true;
		} {
			if(n%i==0) return true;
		} if(n%i==0) return true; n%i==0 n%i n i 0 return true; true return false; false int n n public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	} gcd {
		if(a%b==0) return b;
		else return gcd(b,a%b);
	} if(a%b==0) return b;
		else return gcd(b,a%b); a%b==0 a%b a b 0 return b; b return gcd(b,a%b); gcd(b,a%b) gcd b a%b a b int a a int b b public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	} showary {
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	} for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		} int i=0; int i=0; i 0 i<ary.length-1 i ary.length-1 ary.length ary ary.length 1 i++ i++ i {
			System.out.print(ary[i]+" ");
		} {
			System.out.print(ary[i]+" ");
		} System.out.print(ary[i]+" ") System.out.print System.out System System.out ary[i]+" " ary[i] ary i " " cout(ary[ary.length-1]) cout ary[ary.length-1] ary ary.length-1 ary.length ary ary.length 1 int[] ary ary public static void cout(String n){
		System.out.println(n);
	} cout {
		System.out.println(n);
	} System.out.println(n) System.out.println System.out System System.out n String n n public static void cout(int n){
		System.out.println(n);
	} cout {
		System.out.println(n);
	} System.out.println(n) System.out.println System.out System System.out n int n n public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	} cout {
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	} if(n==true){
			cout("true");
		}else{
			cout("false");
		} n==true n true {
			cout("true");
		} cout("true") cout "true" {
			cout("false");
		} cout("false") cout "false" boolean n n public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	}
	
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
} public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	}
	
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
} Main
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		int m = sc.nextInt();
		int[] R = new int[m];
		
		for(int i=0;i<m;i++) R[i] = sc.nextInt();
		
		int mn = R[0];
		int ret = -1000000001;
		for(int i=1;i<m;i++){
			ret = Math.max(ret, R[i]-mn);
			mn = Math.min(mn, R[i]);
		}
		cout(ret);
	}
	
	
	
	public static boolean isPrime(int n){
		for(int i=2;i<=n*n;i++){
			if(n%i==0) return true;
		}
		return false;
	}
	public static int gcd(int a,int b){
		if(a%b==0) return b;
		else return gcd(b,a%b);
	}
	public static void showary(int[] ary){
		for(int i=0;i<ary.length-1;i++){
			System.out.print(ary[i]+" ");
		}
		cout(ary[ary.length-1]);
	}
	public static void cout(String n){
		System.out.println(n);
	}
	
	public static void cout(int n){
		System.out.println(n);
	}
	public static void cout(boolean n){
		if(n==true){
			cout("true");
		}else{
			cout("false");
		}
	}
}