import java.util.Scanner;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args) {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args) {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main (String[] args) {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	} main {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int A [] = new int [n+1]; A new int [n+1] n+1 n 1 for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		} int i=1; int i=1; i 1 i<=n i n i++ i++ i {
			A[i]=sc.nextInt();
		} {
			A[i]=sc.nextInt();
		} A[i]=sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int diff= Integer.MIN_VALUE; diff Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		} int j=1; int j=1; j 1 j<n j n j++ j++ j {
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		} {
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		} min = Math.min(min, A[j]) min Math.min(min, A[j]) Math.min Math min A[j] A j diff = Math.max(diff, A[j+1]-min) diff Math.max(diff, A[j+1]-min) Math.max Math diff A[j+1]-min A[j+1] A j+1 j 1 min System.out.println(diff) System.out.println System.out System System.out diff String[] args args public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args) {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	}
} public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args) {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	}
} Main
import java.util.Scanner;
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main (String[] args) {
		int n = sc.nextInt();	
		int A [] = new int [n+1];
		for (int i=1; i<=n; i++){
			A[i]=sc.nextInt();
		}
		int min = Integer.MAX_VALUE;
		int diff= Integer.MIN_VALUE;
		for (int j=1; j<n; j++){
			min = Math.min(min, A[j]);
			diff = Math.max(diff, A[j+1]-min);
		}
		System.out.println(diff);
	}
}