import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	}
} Main public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	} main {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=Integer.valueOf(sc.next()); n Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc int min=Integer.valueOf(sc.next()); min Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc int dmax=Integer.MIN_VALUE; dmax Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		} {
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		} int next=Integer.valueOf(sc.next()); next Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc int d=next-min; d next-min next min if(d>dmax)dmax=d; d>dmax d dmax dmax=d dmax d if(next<min)min=next; next<min next min min=next min next System.out.println(dmax) System.out.println System.out System System.out dmax String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int min=Integer.valueOf(sc.next());
		int dmax=Integer.MIN_VALUE;
		
		for(int i=1;i<n;i++){
			int next=Integer.valueOf(sc.next());
			int d=next-min;
			if(d>dmax)dmax=d;
			if(next<min)min=next;
		}
		System.out.println(dmax);
	}
}