import java.util.Scanner;

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

public class Main {
	
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int[] r = new int[n];
	    for (int i = 0; i < n; i++) {
			r[i] = scan.nextInt();
		}
	  
	    int min = r[0];
		int margin = r[1] - r[0];
		for (int i = 1; i < r.length; i++) {
			margin = Math.max(margin, r[i] - min);
			min = Math.min(min, r[i]);
		}
		
		System.out.println(margin);
	}
}