import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.Math;

/*Question
/FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????
/????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???(108??? ??? 100???) ?? 1000?????? =
8000??????????????????????????¨?????§????????????
/???????????¨????????????????????? t?????????????????? Rt (t=0,1,2,,,n???1)?????\?????¨??????????????????????????§??????????????? Rj???Ri (????????????j>i??¨??????) ????????§???????±??????????????????????
*/

/*Input
/?????????????????´??° n?????????????????????????¶???? n ????????´??° Rt (t=0,1,2,,,n???1) ????????????????????????????????? 
*/

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		//????????¨
		long k;
		/*??\???
		/??????????´???°?????\???????¬??????°????????\???
		*/
		int n = Integer.parseInt(sc.readLine());
		long[] r = new long[n];
		for(int i = 0;i < n;i++){
			r[i] = Long.parseLong(sc.readLine());
		}
		/*??°??????fxariganetokasu???????????????
		/??????????????£??????????????§??????
		*/
		k = fxariganetokasu(r);
		System.out.println(k);
	}

	/*fxariganetokasu????????????
	/????????????????????????????????§????±???????
	/@return long
	*/

	public static long fxariganetokasu(long[] r) {
		//????????¨?????¨??????????????\???????????????????????????????????\????????????????????????int???????°??????§??????????????????????????????
		long s = r[1] - r[0];
		//????°??????\????????¨????????????????????\????????????
		long minn = r[0];
		for (int i = 1;i < r.length;i++) {
			s = Math.max(s,r[i] - minn);
			minn = Math.min(minn,r[i]);
		}
		return s;
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz