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

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	}
}
 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 final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	}
} Main public static final int BIG_NUM  = 2000000000; BIG_NUM 2000000000 public static final int MOD  = 1000000007; MOD 1000000007 public static void main(String[] args) {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	} main {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	} int N N tmp tmp maximum = -BIG_NUM maximum -BIG_NUM BIG_NUM minimum = BIG_NUM; minimum BIG_NUM BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} NumberFormatException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} N = Integer.parseInt(br.readLine()) N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			} int loop = 0; int loop = 0; loop 0 loop < N loop N loop++ loop++ loop {
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			} {
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			} tmp = Integer.parseInt(br.readLine()) tmp Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br maximum = Math.max(maximum, tmp-minimum) maximum Math.max(maximum, tmp-minimum) Math.max Math maximum tmp-minimum tmp minimum minimum = Math.min(minimum, tmp) minimum Math.min(minimum, tmp) Math.min Math minimum tmp System.out.println(maximum) System.out.println System.out System System.out maximum String[] args args public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	}
} public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		try {
			N = Integer.parseInt(br.readLine());

			for(int loop = 0; loop < N; loop++){
				tmp = Integer.parseInt(br.readLine());
				maximum = Math.max(maximum, tmp-minimum);
				minimum = Math.min(minimum, tmp);
			}
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}

		System.out.println(maximum);
	}
}

