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

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	}
} Main public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	} 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 minv = 0; minv 0 int maxv = Integer.MIN_VALUE; maxv Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		} {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		} int input = Integer.parseInt(br.readLine()); input Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br if (i == 0) {
				minv = input;
				continue;
			} i == 0 i 0 {
				minv = input;
				continue;
			} minv = input minv input continue; maxv = maxv < (input - minv) ? (input - minv) : maxv maxv maxv < (input - minv) ? (input - minv) : maxv maxv < (input - minv) maxv (input - minv) input minv (input - minv) input minv maxv minv = minv > input ? input : minv minv minv > input ? input : minv minv > input minv input input minv System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());

		int minv = 0;
		int maxv = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			int input = Integer.parseInt(br.readLine());
			if (i == 0) {
				minv = input;
				continue;
			}
			maxv = maxv < (input - minv) ? (input - minv) : maxv;
			minv = minv > input ? input : minv;
		}
		System.out.println(maxv);
	}
}