import java.util.*;

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

		int ans = -1000000000;
		int min = stdIn.nextInt();

		for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		}

		System.out.println(ans);
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

		int ans = -1000000000;
		int min = stdIn.nextInt();

		for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		}

		System.out.println(ans);
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

		int ans = -1000000000;
		int min = stdIn.nextInt();

		for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		}

		System.out.println(ans);
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();

		int ans = -1000000000;
		int min = stdIn.nextInt();

		for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		}

		System.out.println(ans);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int ans = -1000000000; ans -1000000000 1000000000 int min = stdIn.nextInt(); min stdIn.nextInt() stdIn.nextInt stdIn for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		} {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		} int r = stdIn.nextInt(); r stdIn.nextInt() stdIn.nextInt stdIn ans = Math.max(ans,r-min) ans Math.max(ans,r-min) Math.max Math ans r-min r min min = Math.min(min,r) min Math.min(min,r) Math.min Math min r System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;

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

		int ans = -1000000000;
		int min = stdIn.nextInt();

		for (int i=1; i<n; i++) {
			int r = stdIn.nextInt();
			ans = Math.max(ans,r-min);
			min = Math.min(min,r);
		}

		System.out.println(ans);
	}
}