import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int inputNumTimes = Integer.parseInt(br.readLine()); inputNumTimes Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] value = new int[inputNumTimes]; value new int[inputNumTimes] inputNumTimes for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		} int i = 0; int i = 0; i 0 i < inputNumTimes i inputNumTimes i++ i++ i {
			value[i] = Integer.parseInt(br.readLine());
		} {
			value[i] = Integer.parseInt(br.readLine());
		} value[i] = Integer.parseInt(br.readLine()) value[i] value i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int minValue = value[0]; minValue value[0] value 0 int maxValue = value[1] - value[0]; maxValue value[1] - value[0] value[1] value 1 value[0] value 0 for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		} int i = 1; int i = 1; i 1 i < inputNumTimes i inputNumTimes i++ i++ i {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		} {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		} maxValue = Math.max(maxValue, value[i] - minValue) maxValue Math.max(maxValue, value[i] - minValue) Math.max Math maxValue value[i] - minValue value[i] value i minValue minValue = Math.min(minValue, value[i]) minValue Math.min(minValue, value[i]) Math.min Math minValue value[i] value i System.out.println(maxValue) System.out.println System.out System System.out maxValue String[] args args public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
} public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
}