import java.util.Scanner;

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		int max = 1 - (int) Math.pow(10, 9);
		int ri = scanner.nextInt();
		for (int i = 1; i < n; i++) {
			int rj = scanner.nextInt();
			max = Math.max(max, rj - ri);
			ri = Math.min(ri, rj); 
		}
		
		scanner.close();
		
		System.out.println(max);
	}
} 

