import java.util.Scanner;

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;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

		System.out.println(maximum);
	}
}
 import java.util.Scanner; Scanner java.util 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;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

		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;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

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


		int N,tmp,maximum = -BIG_NUM,minimum = BIG_NUM;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

		System.out.println(maximum);
	} int N N tmp tmp maximum = -BIG_NUM maximum -BIG_NUM BIG_NUM minimum = BIG_NUM; minimum BIG_NUM Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) N = scanner.nextInt() N scanner.nextInt() scanner.nextInt scanner for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			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 = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		} {
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		} tmp = scanner.nextInt() tmp scanner.nextInt() scanner.nextInt scanner 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;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

		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;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

		System.out.println(maximum);
	}
} Main
import java.util.Scanner;

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;
		Scanner scanner = new Scanner(System.in);

		N = scanner.nextInt();

		for(int loop = 0; loop < N; loop++){
			tmp = scanner.nextInt();
			maximum = Math.max(maximum, tmp-minimum);
			minimum = Math.min(minimum, tmp);
		}

		System.out.println(maximum);
	}
}

