import java.util.Scanner;

public class Main {

	public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	}

}
 import java.util.Scanner; Scanner java.util public class Main {

	public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	}

} Main public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	} get_max_profit {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	} if (a.length == 0)
			return 0; a.length == 0 a.length a a.length 0 return 0; 0 int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = a[0]; min a[0] a 0 for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		} int i = 1; int i = 1; i 1 i < a.length i a.length a a.length i++ i++ i {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		} {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		} max = Math.max(a[i] - min, max) max Math.max(a[i] - min, max) Math.max Math a[i] - min a[i] a i min max min = Math.min(a[i], min) min Math.min(a[i], min) Math.min Math a[i] a i min return max; max int[] a a public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	} main {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int n = s.nextInt(); n s.nextInt() s.nextInt s int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = s.nextInt();
		} {
			a[i] = s.nextInt();
		} a[i] = s.nextInt() a[i] a i s.nextInt() s.nextInt s System.out.println(get_max_profit(a)) System.out.println System.out System System.out get_max_profit(a) get_max_profit a String[] args args public class Main {

	public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	}

} public class Main {

	public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	}

} Main
import java.util.Scanner;

public class Main {

	public static int get_max_profit(int[] a) {
		if (a.length == 0)
			return 0;
		int max = Integer.MIN_VALUE;
		int min = a[0];
		for (int i = 1; i < a.length; i++) {
			max = Math.max(a[i] - min, max);
			min = Math.min(a[i], min);
		}
		return max;
	}

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = s.nextInt();
		}
		System.out.println(get_max_profit(a));
	}

}

