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

public class Main {
	public static void main(String[] args) {
		final int[] list = getList();
		final int diff = getMaxDiff(list);
		
		System.out.println(diff);
	}
	
	public static int getMaxDiff(int[] list) {
        int maxDiff = list[1] - list[0];
        int min = list[0];
        
        int diff;
        for (int i = 2; i < list.length; i++) {
        	if (list[i-1] < min) min = list[i-1];
        	diff = list[i] - min;
        	if (maxDiff < diff) maxDiff = diff;
        }
         
        return maxDiff;
    }
	
	public static int[] getList() {
		int[] list = null;
		
		try {
			final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
			final int n = Integer.parseInt(reader.readLine());
			list = new int[n];
			for (int i = 0; i < n; i++) {
				list[i] = Integer.parseInt(reader.readLine());
			}
			reader.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return list;
	}
}
/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