import java.util.Scanner;

public class Main {
	int[] min = new int[2];
	
	void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	}
	
	void searchMinimun(int[] array, int n) {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	int[] min = new int[2];
	
	void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	}
	
	void searchMinimun(int[] array, int n) {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main int[] min = new int[2]; min new int[2] 2 void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	} run {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] array = new int[200000]; array new int[200000] 200000 for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			array[i] = scan.nextInt();
		} {
			array[i] = scan.nextInt();
		} array[i] = scan.nextInt() array[i] array i scan.nextInt() scan.nextInt scan int max = -1000000000; max -1000000000 1000000000 searchMinimun(array, n-1) searchMinimun array n-1 n 1 for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		} int i = n-1; int i = n-1; i n-1 n 1 i > 0 i 0 i-- i-- i {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		} {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		} if(min[1] == i) searchMinimun(array, i-1); min[1] == i min[1] min 1 i searchMinimun(array, i-1) searchMinimun array i-1 i 1 int tmp = array[i] - min[0]; tmp array[i] - min[0] array[i] array i min[0] min 0 if(tmp > max) max = tmp; tmp > max tmp max max = tmp max tmp System.out.println(max) System.out.println System.out System System.out max void searchMinimun(int[] array, int n) {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	} searchMinimun {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	} min[0] = array[0] min[0] min 0 array[0] array 0 min[1] = 0 min[1] min 1 0 for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		} int i = 1; int i = 1; i 1 i <= n i n i++ i++ i {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		} {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		} if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			} min[0] > array[i] min[0] min 0 array[i] array i {
				min[0] = array[i];
				min[1] = i;
			} min[0] = array[i] min[0] min 0 array[i] array i min[1] = i min[1] min 1 i int[] array array int n n public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	int[] min = new int[2];
	
	void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	}
	
	void searchMinimun(int[] array, int n) {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	int[] min = new int[2];
	
	void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	}
	
	void searchMinimun(int[] array, int n) {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.Scanner;

public class Main {
	int[] min = new int[2];
	
	void run() {
		// 入力
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] array = new int[200000];
		for(int i = 0; i < n; i++) {
			array[i] = scan.nextInt();
		}
		int max = -1000000000;	
		searchMinimun(array, n-1);
		for(int i = n-1; i > 0; i--) {
			if(min[1] == i) searchMinimun(array, i-1);
			int tmp = array[i] - min[0];
			if(tmp > max) max = tmp;
		}
		System.out.println(max);
	}
	
	void searchMinimun(int[] array, int n) {
		min[0] = array[0];
		min[1] = 0;
		for(int i = 1; i <= n; i++) {
			if(min[0] > array[i]) {
				min[0] = array[i];
				min[1] = i;
			}
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}
}
