import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long dMax = -1000000001; dMax -1000000001 1000000001 long min = sc.nextLong(); min sc.nextLong() sc.nextLong sc for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		} {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		} long r = sc.nextLong(); r sc.nextLong() sc.nextLong sc dMax = Math.max((r - min), dMax) dMax Math.max((r - min), dMax) Math.max Math (r - min) r min dMax min = Math.min(r, min) min Math.min(r, min) Math.min Math r min System.out.println(dMax) System.out.println System.out System System.out dMax sc.close() sc.close sc String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	}
}

