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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	}

} 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 IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	}

} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int minNum = Integer.parseInt(br.readLine()); minNum Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int maxNum = -1000000000; maxNum -1000000000 1000000000 for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		} {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		} int r = Integer.parseInt(br.readLine()); r Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br maxNum = Math.max(maxNum, r - minNum) maxNum Math.max(maxNum, r - minNum) Math.max Math maxNum r - minNum r minNum minNum = Math.min(minNum, r) minNum Math.min(minNum, r) Math.min Math minNum r System.out.println(maxNum) System.out.println System.out System System.out maxNum String[] args args public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	}

} public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	}

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

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine()); // 整数の個数
		int minNum = Integer.parseInt(br.readLine()); // 最小値
		int maxNum = -1000000000; // 差額の最大値
		for (int i = 1; i < n; i++) {
			int r = Integer.parseInt(br.readLine());
			maxNum = Math.max(maxNum, r - minNum);
			minNum = Math.min(minNum, r);
		}
		System.out.println(maxNum);

	}

}
