import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String args[]){
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	}
} Main public static void main(String args[]){
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	} main {
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	} int n n min=0 min 0 a a p=0; p 0 Scanner sc=new Scanner(System.in); sc new Scanner(System.in) n=sc.nextInt() n sc.nextInt() sc.nextInt sc for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		} {
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		} a=sc.nextInt() a sc.nextInt() sc.nextInt sc if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			} i>=2 i 2 {
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			} if (a-min>p){p=a-min;} a-min>p a-min a min p {p=a-min;} p=a-min p a-min a min if (a<min){min=a;} a<min a min {min=a;} min=a min a if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			} i==0 i 0 {
				min=a;
			} min=a min a if (i==1){
				p=a-min;
				if (a<min){min=a;}
			} i==1 i 1 {
				p=a-min;
				if (a<min){min=a;}
			} p=a-min p a-min a min if (a<min){min=a;} a<min a min {min=a;} min=a min a System.out.println(p) System.out.println System.out System System.out p String args[] args public class Main {
	public static void main(String args[]){
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	}
} public class Main {
	public static void main(String args[]){
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		int n,min=0,a,p=0;
		Scanner sc=new Scanner(System.in);
		n=sc.nextInt();
		for (int i=0;i<n;i++){
			a=sc.nextInt();
			if (i>=2){
				if (a-min>p){p=a-min;}
				if (a<min){min=a;}
			}else if (i==0){
				min=a;
			}else if (i==1){
				p=a-min;
				if (a<min){min=a;}
			}
		}
		System.out.println(p);
	}
}