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

public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	}
} Main private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	} main {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	} int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int maxv = Integer.MIN_VALUE; maxv Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		} {
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		} int r = Integer.parseInt(br.readLine()); r Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br maxv = Math.max(maxv, r - min) maxv Math.max(maxv, r - min) Math.max Math maxv r - min r min min = Math.min(min, r) min Math.min(min, r) Math.min Math min r System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	}
} public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	
	private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	
	
	public static void main(String[] args) throws NumberFormatException, IOException {
		int n = Integer.parseInt(br.readLine());
		
		int maxv = Integer.MIN_VALUE;
		int min = Integer.MAX_VALUE;
		
		for(int i = 0; i < n; i++){
			int r = Integer.parseInt(br.readLine());
			maxv = Math.max(maxv, r - min);
			min = Math.min(min, r);
		}
		
		System.out.println(maxv);
		
	}
}
