import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	}

	private static int maxProfit(int[] R) {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	}

	private static int[] inpNum(int n) {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	}
} import java.util.Scanner; Scanner java.util public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	}

	private static int maxProfit(int[] R) {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	}

	private static int[] inpNum(int n) {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	} main {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	} int t = sc.nextInt(); t sc.nextInt() sc.nextInt sc int[] R = inpNum(t); R inpNum(t) inpNum t int mp = maxProfit(R); mp maxProfit(R) maxProfit R System.out.println(mp) System.out.println System.out System System.out mp sc.close() sc.close sc String[] args args private static int maxProfit(int[] R) {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	} maxProfit {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	} int max_p = R[1] - R[0]; max_p R[1] - R[0] R[1] R 1 R[0] R 0 int min_p = R[0]; min_p R[0] R 0 for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			} int j = 1; int j = 1; j 1 j < R.length j R.length R R.length j++ j++ j {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			} {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			} max_p = Math.max(max_p, R[j] - min_p) max_p Math.max(max_p, R[j] - min_p) Math.max Math max_p R[j] - min_p R[j] R j min_p min_p = Math.min(min_p, R[j]) min_p Math.min(min_p, R[j]) Math.min Math min_p R[j] R j return max_p; max_p int[] R R private static int[] inpNum(int n) {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	} inpNum {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	} int[] nums = new int[n]; nums new int[n] n for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			nums[i] = sc.nextInt();
		} {
			nums[i] = sc.nextInt();
		} nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc return nums; nums int n n public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	}

	private static int maxProfit(int[] R) {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	}

	private static int[] inpNum(int n) {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	}
} public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	}

	private static int maxProfit(int[] R) {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	}

	private static int[] inpNum(int n) {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	}
} Main
import java.util.Scanner;

public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int t = sc.nextInt();
		int[] R = inpNum(t);

		int mp = maxProfit(R);
		System.out.println(mp);
		sc.close();
	}

	private static int maxProfit(int[] R) {
		int max_p = R[1] - R[0];
		int min_p = R[0];
			for(int j = 1; j < R.length; j++) {
					max_p = Math.max(max_p, R[j] - min_p);
					min_p = Math.min(min_p, R[j]);
			}
		return max_p;
	}

	private static int[] inpNum(int n) {
		int[] nums = new int[n];

		for (int i = 0; i < n; i++) {
			nums[i] = sc.nextInt();
		}
		return nums;
	}
}
