import java.util.Scanner;

class Main {
    public static void main (String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int R[] = new int[n];
	int max = (int)Math.pow(10,10)*(-1),min;
	for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	}
	min = R[0];
	for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	}
       	System.out.println(max);
    }
}



 import java.util.Scanner; Scanner java.util class Main {
    public static void main (String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int R[] = new int[n];
	int max = (int)Math.pow(10,10)*(-1),min;
	for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	}
	min = R[0];
	for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	}
       	System.out.println(max);
    }
} Main public static void main (String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int R[] = new int[n];
	int max = (int)Math.pow(10,10)*(-1),min;
	for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	}
	min = R[0];
	for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	}
       	System.out.println(max);
    } main {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int R[] = new int[n];
	int max = (int)Math.pow(10,10)*(-1),min;
	for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	}
	min = R[0];
	for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	}
       	System.out.println(max);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int R[] = new int[n]; R new int[n] n int max = (int)Math.pow(10,10)*(-1) max (int)Math.pow(10,10)*(-1) (int)Math.pow(10,10) Math.pow Math 10 10 (-1) 1 min; min for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
	    R[i] = sc.nextInt();
	} {
	    R[i] = sc.nextInt();
	} R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc min = R[0] min R[0] R 0 for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	} int j = 1; int j = 1; j 1 j < n j n j++ j++ j {	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	} {	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	} max = Math.max(max,(R[j] - min)) max Math.max(max,(R[j] - min)) Math.max Math max (R[j] - min) R[j] R j min min = Math.min(min,R[j]) min Math.min(min,R[j]) Math.min Math min R[j] R j System.out.println(max) System.out.println System.out System System.out max String args[] args
import java.util.Scanner;

class Main {
    public static void main (String args[]) {
	Scanner sc = new Scanner(System.in);
	int n = sc.nextInt();
	int R[] = new int[n];
	int max = (int)Math.pow(10,10)*(-1),min;
	for(int i = 0;i < n;i++){
	    R[i] = sc.nextInt();
	}
	min = R[0];
	for(int j = 1;j < n;j++){	    
	    max = Math.max(max,(R[j] - min));
	    min = Math.min(min,R[j]);
	}
       	System.out.println(max);
    }
}




