import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	}
} Main public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	} main {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int v = Integer.parseInt(line); v Integer.parseInt(line) Integer.parseInt Integer line int[] vs = new int[v]; vs new int[v] v for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		} int i = 0; int i = 0; i 0 i < v i v i++ i++ i {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		} {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		} String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc vs[i] = Integer.parseInt(line2) vs[i] vs i Integer.parseInt(line2) Integer.parseInt Integer line2 int min = vs[0]; min vs[0] vs 0 int max = vs[1]-vs[0]; max vs[1]-vs[0] vs[1] vs 1 vs[0] vs 0 for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			} int i = 1; int i = 1; i 1 i < v i v i++ i++ i {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			} {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			} if (max<vs[i]-min) {
				max=vs[i]-min;
			} max<vs[i]-min max vs[i]-min vs[i] vs i min {
				max=vs[i]-min;
			} max=vs[i]-min max vs[i]-min vs[i] vs i min if (min>vs[i]) {
				min=vs[i];
			} min>vs[i] min vs[i] vs i {
				min=vs[i];
			} min=vs[i] min vs[i] vs i System.out.println(max) System.out.println System.out System System.out max String[] arges arges public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	}
} public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		for (int i = 0; i < v; i++) {
			String line2 = sc.nextLine();
			vs[i] = Integer.parseInt(line2);
		}

		int min = vs[0];
		int max = vs[1]-vs[0];
		for (int i = 1; i < v; i++) {
			if (max<vs[i]-min) {
				max=vs[i]-min;
			}
			if (min>vs[i]) {
				min=vs[i];
			}
			}
		System.out.println(max);

	}
}