import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	}
	public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	}
	
} import java.util.ArrayList; ArrayList java.util import java.util.Scanner; Scanner java.util public class Main {
	public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	}
	public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	}
	
} Main public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	} max_profit {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	} int min_val = arr.get(0); min_val arr.get(0) arr.get arr 0 int max_val = -Integer.MIN_VALUE; max_val -Integer.MIN_VALUE Integer.MIN_VALUE Integer Integer.MIN_VALUE int i = 1; i 1 while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		} i < arr.size() i arr.size() arr.size arr {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		} max_val = Math.max(max_val, arr.get(i) - min_val) max_val Math.max(max_val, arr.get(i) - min_val) Math.max Math max_val arr.get(i) - min_val arr.get(i) arr.get arr i min_val min_val = Math.min(min_val, arr.get(i)) min_val Math.min(min_val, arr.get(i)) Math.min Math min_val arr.get(i) arr.get arr i i++ i return max_val; max_val ArrayList<Integer> arr arr public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	} main {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	} Scanner br = new Scanner(System.in); br new Scanner(System.in) int len; len len = br.nextInt() len br.nextInt() br.nextInt br ArrayList<Integer> arr= new ArrayList<Integer>(); arr new ArrayList<Integer>() int val = 0; val 0 while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		} len > 0 len 0 {
			val = br.nextInt();
			arr.add(val);
			len --;
		} val = br.nextInt() val br.nextInt() br.nextInt br arr.add(val) arr.add arr val len -- len System.out.println(max_profit(arr)) System.out.println System.out System System.out max_profit(arr) max_profit arr br.close() br.close br String [] args args public class Main {
	public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	}
	public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	}
	
} public class Main {
	public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	}
	public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	}
	
} Main
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static int max_profit(ArrayList<Integer> arr) {
		int min_val = arr.get(0);
		int max_val = -Integer.MIN_VALUE;
		
		int i = 1;
		while(i < arr.size()) {
			max_val = Math.max(max_val, arr.get(i) - min_val);
			min_val = Math.min(min_val, arr.get(i));
			i++;
		}
		
		
		return max_val;
	}
	public static void main(String [] args) {
		Scanner br = new Scanner(System.in);
		int len;
		
		len = br.nextInt();
		ArrayList<Integer> arr= new ArrayList<Integer>();
		int val = 0;
		while(len > 0) {
			val = br.nextInt();
			arr.add(val);
			len --;
		}
		
		
		//invoke the computation part
		System.out.println(max_profit(arr));
		br.close();
		
	}
	
}