import java.util.Scanner;
public class Main{
    public static void main(String[] args){
	int i,j,maxago=Integer.MIN_VALUE,min,max=Integer.MIN_VALUE;
	
	Scanner sca = new Scanner(System.in);
	i=sca.nextInt();
	int[] hai= new int[i];
	hai[0]=sca.nextInt();
	min=hai[0];
	for(i=1;i<hai.length;i++){//i->max(assuming)
	    hai[i]=sca.nextInt();
	    if(hai[i]-min>maxago){
		max=hai[i];
		maxago=max-min;
	    }
	    if(hai[i]<min){
		min=hai[i];
	    }
	    
	}
	System.out.println(maxago);
    }
}


/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