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

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int inputNumTimes = Integer.parseInt(br.readLine());

		int[] value = new int[inputNumTimes];

		for(int i = 0; i < inputNumTimes; i++) {
			value[i] = Integer.parseInt(br.readLine());
		}

		int minValue = value[0];
		int maxValue = value[1] - value[0];

		for(int i = 1; i < inputNumTimes; i++) {
			maxValue = Math.max(maxValue, value[i] - minValue);
			minValue = Math.min(minValue, value[i]);
		}
		System.out.println(maxValue);
	}
}
/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