/**
 * ?????§?????????
 * FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????
 * <p>
 * ???????????¨?????????????????????t?????????????????? Rt(t=0,1,2,,,n???1)?????\?????¨??????????????????????????§??????????????? Rj???Ri (?????????,j>i??¨??????) ????????§???????±??????????????????????
 * <p>
 * ??\???
 * ?????????????????´??°n?????????????????????????¶????n????????´??° Rt(t=0,1,2,,,n???1) ?????????????????????????????????
 * <p>
 * ??????
 * ?????§??????????????????????????????????????????
 * <p>
 * ??¶?´?
 * 2???n???200,000
 * 1???Rt???10e9
 */

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	} main {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int t = stdIn.nextInt(); t stdIn.nextInt() stdIn.nextInt stdIn int[] profitT = new int[t]; profitT new int[t] t for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		} int i = 0; int i = 0; i 0 i < t i t i++ i++ i {
			profitT[i] = stdIn.nextInt();
		} {
			profitT[i] = stdIn.nextInt();
		} profitT[i] = stdIn.nextInt() profitT[i] profitT i stdIn.nextInt() stdIn.nextInt stdIn int maxProfit = profitT[1] - profitT[0]; maxProfit profitT[1] - profitT[0] profitT[1] profitT 1 profitT[0] profitT 0 int min = profitT[0]; min profitT[0] profitT 0 for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		} int i = 1; int i = 1; i 1 i < t i t i++ i++ i {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		} {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		} if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			} maxProfit < profitT[i] - min maxProfit profitT[i] - min profitT[i] profitT i min {
				maxProfit = profitT[i] - min;
			} maxProfit = profitT[i] - min maxProfit profitT[i] - min profitT[i] profitT i min if (min > profitT[i]) {
				min = profitT[i];
			} min > profitT[i] min profitT[i] profitT i {
				min = profitT[i];
			} min = profitT[i] min profitT[i] profitT i System.out.println(maxProfit) System.out.println System.out System System.out maxProfit String[] args args public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	}
} Main
/**
 * ?????§?????????
 * FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???(108??? ?????? 100???) ???? 1000?????? == 8000??????????????????????????¨?????§????????????
 * <p>
 * ???????????¨?????????????????????t?????????????????? Rt(t=0,1,2,,,n???1)?????\?????¨??????????????????????????§??????????????? Rj???Ri (?????????,j>i??¨??????) ????????§???????±??????????????????????
 * <p>
 * ??\???
 * ?????????????????´??°n?????????????????????????¶????n????????´??° Rt(t=0,1,2,,,n???1) ?????????????????????????????????
 * <p>
 * ??????
 * ?????§??????????????????????????????????????????
 * <p>
 * ??¶?´?
 * 2???n???200,000
 * 1???Rt???10e9
 */

import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);

		int t = stdIn.nextInt();
		int[] profitT = new int[t];

		for (int i = 0; i < t; i++) {
			profitT[i] = stdIn.nextInt();
		}

		int maxProfit = profitT[1] - profitT[0];

		int min = profitT[0];
		for (int i = 1; i < t; i++) {
			if (maxProfit < profitT[i] - min) {
				maxProfit = profitT[i] - min;
			}
			if (min > profitT[i]) {
				min = profitT[i];
			}
		}
		System.out.println(maxProfit);
	}
}