import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	}
} import java.util.Arrays; Arrays java.util import java.util.HashMap; HashMap java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	}
} Main public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	} main {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) final int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = sc.nextInt();
		} {
			arr[i] = sc.nextInt();
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int max = arr[n - 1]; max arr[n - 1] arr n - 1 n 1 int diff_max = Integer.MIN_VALUE; diff_max Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		} int i = n - 2; int i = n - 2; i n - 2 n 2 i >= 0 i 0 i-- i-- i {
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		} {
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		} diff_max = Math.max(diff_max, max - arr[i]) diff_max Math.max(diff_max, max - arr[i]) Math.max Math diff_max max - arr[i] max arr[i] arr i max = Math.max(max, arr[i]) max Math.max(max, arr[i]) Math.max Math max arr[i] arr i System.out.println(diff_max) System.out.println System.out System System.out diff_max String args[] args public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	}
} public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	}
} Main
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
	
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		
		final int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = sc.nextInt();
		}
		
		int max = arr[n - 1];
		int diff_max = Integer.MIN_VALUE;
		for(int i = n - 2; i >= 0; i--){
			diff_max = Math.max(diff_max, max - arr[i]);
			
			max = Math.max(max, arr[i]);
		}
		
		
		System.out.println(diff_max);
		
	}
}