import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	}

}

 import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	}

} Main public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	} main {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	} Scanner in=new Scanner(System.in); in new Scanner(System.in) int n=in.nextInt() n in.nextInt() in.nextInt in A[]=new int[n]; A new int[n] n for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			A[i]=Integer.parseInt(in.next());
		} {
			A[i]=Integer.parseInt(in.next());
		} A[i]=Integer.parseInt(in.next()) A[i] A i Integer.parseInt(in.next()) Integer.parseInt Integer in.next() in.next in int min=A[0] min A[0] A 0 max=A[1]-A[0]; max A[1]-A[0] A[1] A 1 A[0] A 0 for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		} {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		} max=Math.max(max,A[i]-min) max Math.max(max,A[i]-min) Math.max Math max A[i]-min A[i] A i min min=Math.min(min,A[i]) min Math.min(min,A[i]) Math.min Math min A[i] A i System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	}

} Main
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		int n=in.nextInt(),A[]=new int[n];
		for(int i=0;i<n;i++) {
			A[i]=Integer.parseInt(in.next());
		}
		
		int min=A[0],max=A[1]-A[0];
		for(int i=1;i<n;i++) {
			max=Math.max(max,A[i]-min);
			min=Math.min(min,A[i]);
		}
		System.out.println(max);
	}

}


