import java.io.IOException;
import java.util.*;

public class Main {


	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		int sizeOfList = sc.nextInt();
		List<Long> values = new ArrayList<Long>();

		long biggest = -(2000000000-1);
		for (int i = 0; i < sizeOfList; i++) {
			values.add(sc.nextLong());
		}
		long min = values.get(0);
		for (int i = 1; i < values.size(); i++) {
			long diff = values.get(i) - min;
			if (biggest < diff) {
				biggest = diff;
			}
			if (values.get(i) < min) {
				min = values.get(i);
			}
		}

		System.out.println(biggest);
	}
}
/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