import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	} main {
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		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[] nums = new int[n]; nums new int[n] n for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<nums.length i nums.length nums nums.length i++ i++ i {
			nums[i] = sc.nextInt();
		} {
			nums[i] = sc.nextInt();
		} nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = nums[0]; min nums[0] nums 0 for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		} int i=1; int i=1; i 1 i<nums.length i nums.length nums nums.length i++ i++ i {
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		} {
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		} max = Math.max(max, nums[i]-min) max Math.max(max, nums[i]-min) Math.max Math max nums[i]-min nums[i] nums i min min = Math.min(min, nums[i]) min Math.min(min, nums[i]) Math.min Math min nums[i] nums i 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 sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	}
} public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	}
} Main
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int  n  = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<nums.length;i++){
			nums[i] = sc.nextInt();
		}
		int max = Integer.MIN_VALUE;
		int min = nums[0];
		for(int i=1;i<nums.length;i++){
			max = Math.max(max, nums[i]-min);
			min = Math.min(min, nums[i]);
		}
		System.out.println(max);
	}
}