import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	}
} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	} main {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int number[] = new int[n]; number new int[n] n for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int x = scanner.nextInt();
			number[i] = x;
		} {
			int x = scanner.nextInt();
			number[i] = x;
		} int x = scanner.nextInt(); x scanner.nextInt() scanner.nextInt scanner number[i] = x number[i] number i x int min = number[0]; min number[0] number 0 int max = number[1] - number[0]; max number[1] - number[0] number[1] number 1 number[0] number 0 for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		} {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		} if (max < number[i] - min) {
				max = number[i] - min;
			} max < number[i] - min max number[i] - min number[i] number i min {
				max = number[i] - min;
			} max = number[i] - min max number[i] - min number[i] number i min if (min > number[i]) {
				min = number[i];
			} min > number[i] min number[i] number i {
				min = number[i];
			} min = number[i] min number[i] number i System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int number[] = new int[n];
		for (int i = 0; i < n; i++) {
			int x = scanner.nextInt();
			number[i] = x;
		}
		int min = number[0];
		int max = number[1] - number[0];
		for (int i = 1; i < n; i++) {
			if (max < number[i] - min) {
				max = number[i] - min;
			}
			if (min > number[i]) {
				min = number[i];
			}
		}
		System.out.println(max);
	}
}
