import java.util.Scanner;
class Main {
	static final int MAX = 200000;
	public static void main(String[] args) {
		int[] R = new int[MAX];
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i = 0;i<n;i++) R[i] = in.nextInt();
		
		int maxv = R[1]-R[0];
		int minv = R[0];
		for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		}
		System.out.println(maxv);
	}
} import java.util.Scanner; Scanner java.util class Main {
	static final int MAX = 200000;
	public static void main(String[] args) {
		int[] R = new int[MAX];
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i = 0;i<n;i++) R[i] = in.nextInt();
		
		int maxv = R[1]-R[0];
		int minv = R[0];
		for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		}
		System.out.println(maxv);
	}
} Main static final int MAX = 200000; MAX 200000 public static void main(String[] args) {
		int[] R = new int[MAX];
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i = 0;i<n;i++) R[i] = in.nextInt();
		
		int maxv = R[1]-R[0];
		int minv = R[0];
		for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		}
		System.out.println(maxv);
	} main {
		int[] R = new int[MAX];
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i = 0;i<n;i++) R[i] = in.nextInt();
		
		int maxv = R[1]-R[0];
		int minv = R[0];
		for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		}
		System.out.println(maxv);
	} int[] R = new int[MAX]; R new int[MAX] MAX int n; n Scanner in = new Scanner(System.in); in new Scanner(System.in) n = in.nextInt() n in.nextInt() in.nextInt in for(int i = 0;i<n;i++) R[i] = in.nextInt(); int i = 0; int i = 0; i 0 i<n i n i++ i++ i R[i] = in.nextInt(); R[i] = in.nextInt() R[i] R i in.nextInt() in.nextInt in int maxv = R[1]-R[0]; maxv R[1]-R[0] R[1] R 1 R[0] R 0 int minv = R[0]; minv R[0] R 0 for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		} int i = 1; int i = 1; i 1 i<n i n i++ i++ i {
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		} {
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		} if(maxv < R[i] - minv) maxv = R[i]-minv; maxv < R[i] - minv maxv R[i] - minv R[i] R i minv maxv = R[i]-minv maxv R[i]-minv R[i] R i minv if(minv>R[i]) minv = R[i]; minv>R[i] minv R[i] R i minv = R[i] minv R[i] R i System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args
import java.util.Scanner;
class Main {
	static final int MAX = 200000;
	public static void main(String[] args) {
		int[] R = new int[MAX];
		int n;
		Scanner in = new Scanner(System.in);
		n = in.nextInt();
		for(int i = 0;i<n;i++) R[i] = in.nextInt();
		
		int maxv = R[1]-R[0];
		int minv = R[0];
		for(int i = 1;i<n;i++){
			if(maxv < R[i] - minv) maxv = R[i]-minv;	
			if(minv>R[i]) minv = R[i];
		}
		System.out.println(maxv);
	}
}