import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int n = 0;
		int minv = 0;
		int maxv = 0;
		
		int R[];
		
		n = Integer.parseInt(as.next());
		
		R = new int[n];
		
		for(int i=0;i<n;i++){
			
			R[i] = Integer.parseInt(as.next());
			
		}
		
		minv = R[0];
		maxv = R[1] - R[0];
		
		for(int i=1;i<n;i++){
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		}
		
		sb.append(maxv);
		System.out.println(sb.toString());

	}

} import java.util.Scanner; Scanner java.util class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int n = 0;
		int minv = 0;
		int maxv = 0;
		
		int R[];
		
		n = Integer.parseInt(as.next());
		
		R = new int[n];
		
		for(int i=0;i<n;i++){
			
			R[i] = Integer.parseInt(as.next());
			
		}
		
		minv = R[0];
		maxv = R[1] - R[0];
		
		for(int i=1;i<n;i++){
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		}
		
		sb.append(maxv);
		System.out.println(sb.toString());

	}

} Main /**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int n = 0;
		int minv = 0;
		int maxv = 0;
		
		int R[];
		
		n = Integer.parseInt(as.next());
		
		R = new int[n];
		
		for(int i=0;i<n;i++){
			
			R[i] = Integer.parseInt(as.next());
			
		}
		
		minv = R[0];
		maxv = R[1] - R[0];
		
		for(int i=1;i<n;i++){
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		}
		
		sb.append(maxv);
		System.out.println(sb.toString());

	} main {
		// TODO Auto-generated method stub
		
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int n = 0;
		int minv = 0;
		int maxv = 0;
		
		int R[];
		
		n = Integer.parseInt(as.next());
		
		R = new int[n];
		
		for(int i=0;i<n;i++){
			
			R[i] = Integer.parseInt(as.next());
			
		}
		
		minv = R[0];
		maxv = R[1] - R[0];
		
		for(int i=1;i<n;i++){
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		}
		
		sb.append(maxv);
		System.out.println(sb.toString());

	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() Scanner as = new Scanner(System.in); as new Scanner(System.in) int n = 0; n 0 int minv = 0; minv 0 int maxv = 0; maxv 0 int R[]; R n = Integer.parseInt(as.next()) n Integer.parseInt(as.next()) Integer.parseInt Integer as.next() as.next as R = new int[n] R new int[n] n for(int i=0;i<n;i++){
			
			R[i] = Integer.parseInt(as.next());
			
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			
			R[i] = Integer.parseInt(as.next());
			
		} {
			
			R[i] = Integer.parseInt(as.next());
			
		} R[i] = Integer.parseInt(as.next()) R[i] R i Integer.parseInt(as.next()) Integer.parseInt Integer as.next() as.next as minv = R[0] minv R[0] R 0 maxv = R[1] - R[0] maxv R[1] - R[0] R[1] R 1 R[0] R 0 for(int i=1;i<n;i++){
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		} {
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		} if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			} maxv < (R[i] - minv) maxv (R[i] - minv) R[i] R i minv {
				
				maxv = (R[i] - minv);
				
			} maxv = (R[i] - minv) maxv (R[i] - minv) R[i] R i minv if(minv > R[i]){
				
				minv = R[i];
				
			} minv > R[i] minv R[i] R i {
				
				minv = R[i];
				
			} minv = R[i] minv R[i] R i sb.append(maxv) sb.append sb maxv System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb String[] args args
import java.util.Scanner;

/**
 * 
 */

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		StringBuilder sb = new StringBuilder();
		Scanner as = new Scanner(System.in);
		
		int n = 0;
		int minv = 0;
		int maxv = 0;
		
		int R[];
		
		n = Integer.parseInt(as.next());
		
		R = new int[n];
		
		for(int i=0;i<n;i++){
			
			R[i] = Integer.parseInt(as.next());
			
		}
		
		minv = R[0];
		maxv = R[1] - R[0];
		
		for(int i=1;i<n;i++){
			
			if(maxv < (R[i] - minv)){
				
				maxv = (R[i] - minv);
				
			}
			if(minv > R[i]){
				
				minv = R[i];
				
			}
			
		}
		
		sb.append(maxv);
		System.out.println(sb.toString());

	}

}