import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = in.nextInt();
		}
		int[] max = new int[n];
		max[n-1] = r[n-1];
		for (int i = n - 2; i > 0; i--) {
			max[i] = Math.max(max[i+1], r[i]);
		}
		int[] min = new int[n];
		min[0] = r[0];
		for (int i = 1; i < n; i++) {
			min[i] = Math.min(min[i-1], r[i]);
		}
		int ret = 0x80000000;
		for (int i = 1; i < n; i++) {
			ret = Math.max(ret, max[i] - min[i-1]);
		}
		out.println(ret);
	}
} import java.util.*; util.* java import java.io.*; io.* java class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = in.nextInt();
		}
		int[] max = new int[n];
		max[n-1] = r[n-1];
		for (int i = n - 2; i > 0; i--) {
			max[i] = Math.max(max[i+1], r[i]);
		}
		int[] min = new int[n];
		min[0] = r[0];
		for (int i = 1; i < n; i++) {
			min[i] = Math.min(min[i-1], r[i]);
		}
		int ret = 0x80000000;
		for (int i = 1; i < n; i++) {
			ret = Math.max(ret, max[i] - min[i-1]);
		}
		out.println(ret);
	}
} Main static PrintStream out = System.out; out System.out System System.out static Scanner in = new Scanner(System.in); in new Scanner(System.in) public static void main(String[] args) {
		int n = in.nextInt();
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = in.nextInt();
		}
		int[] max = new int[n];
		max[n-1] = r[n-1];
		for (int i = n - 2; i > 0; i--) {
			max[i] = Math.max(max[i+1], r[i]);
		}
		int[] min = new int[n];
		min[0] = r[0];
		for (int i = 1; i < n; i++) {
			min[i] = Math.min(min[i-1], r[i]);
		}
		int ret = 0x80000000;
		for (int i = 1; i < n; i++) {
			ret = Math.max(ret, max[i] - min[i-1]);
		}
		out.println(ret);
	} main {
		int n = in.nextInt();
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = in.nextInt();
		}
		int[] max = new int[n];
		max[n-1] = r[n-1];
		for (int i = n - 2; i > 0; i--) {
			max[i] = Math.max(max[i+1], r[i]);
		}
		int[] min = new int[n];
		min[0] = r[0];
		for (int i = 1; i < n; i++) {
			min[i] = Math.min(min[i-1], r[i]);
		}
		int ret = 0x80000000;
		for (int i = 1; i < n; i++) {
			ret = Math.max(ret, max[i] - min[i-1]);
		}
		out.println(ret);
	} int n = in.nextInt(); n in.nextInt() in.nextInt in int[] r = new int[n]; r new int[n] n 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] = in.nextInt() r[i] r i in.nextInt() in.nextInt in int[] max = new int[n]; max new int[n] n max[n-1] = r[n-1] max[n-1] max n-1 n 1 r[n-1] r n-1 n 1 for (int i = n - 2; i > 0; i--) {
			max[i] = Math.max(max[i+1], r[i]);
		} int i = n - 2; int i = n - 2; i n - 2 n 2 i > 0 i 0 i-- i-- i {
			max[i] = Math.max(max[i+1], r[i]);
		} {
			max[i] = Math.max(max[i+1], r[i]);
		} max[i] = Math.max(max[i+1], r[i]) max[i] max i Math.max(max[i+1], r[i]) Math.max Math max[i+1] max i+1 i 1 r[i] r i int[] min = new int[n]; min new int[n] n min[0] = r[0] min[0] min 0 r[0] r 0 for (int i = 1; i < n; i++) {
			min[i] = Math.min(min[i-1], r[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			min[i] = Math.min(min[i-1], r[i]);
		} {
			min[i] = Math.min(min[i-1], r[i]);
		} min[i] = Math.min(min[i-1], r[i]) min[i] min i Math.min(min[i-1], r[i]) Math.min Math min[i-1] min i-1 i 1 r[i] r i int ret = 0x80000000; ret 0x80000000 for (int i = 1; i < n; i++) {
			ret = Math.max(ret, max[i] - min[i-1]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			ret = Math.max(ret, max[i] - min[i-1]);
		} {
			ret = Math.max(ret, max[i] - min[i-1]);
		} ret = Math.max(ret, max[i] - min[i-1]) ret Math.max(ret, max[i] - min[i-1]) Math.max Math ret max[i] - min[i-1] max[i] max i min[i-1] min i-1 i 1 out.println(ret) out.println out ret String[] args args
import java.util.*;
import java.io.*;

class Main {
	static PrintStream out = System.out;
	static Scanner in = new Scanner(System.in);

	public static void main(String[] args) {
		int n = in.nextInt();
		int[] r = new int[n];
		for (int i = 0; i < n; i++) {
			r[i] = in.nextInt();
		}
		int[] max = new int[n];
		max[n-1] = r[n-1];
		for (int i = n - 2; i > 0; i--) {
			max[i] = Math.max(max[i+1], r[i]);
		}
		int[] min = new int[n];
		min[0] = r[0];
		for (int i = 1; i < n; i++) {
			min[i] = Math.min(min[i-1], r[i]);
		}
		int ret = 0x80000000;
		for (int i = 1; i < n; i++) {
			ret = Math.max(ret, max[i] - min[i-1]);
		}
		out.println(ret);
	}
}