import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

} import java.sql.Array; Array java.sql import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	} main {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int len = scanner.nextInt(); len scanner.nextInt() scanner.nextInt scanner List<Integer> nums = new ArrayList<Integer>() ; nums new ArrayList<Integer>() for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		} int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
			nums.add(scanner.nextInt());
		} {
			nums.add(scanner.nextInt());
		} nums.add(scanner.nextInt()) nums.add nums scanner.nextInt() scanner.nextInt scanner int min = nums.get(0); min nums.get(0) nums.get nums 0 int profit = -1000000000; profit -1000000000 1000000000 for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		} int i = 1; int i = 1; i 1 i < len i len i++ i++ i {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		} {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		} if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			} profit<(nums.get(i)-min) profit (nums.get(i)-min) nums.get(i) nums.get nums i min {
				profit = nums.get(i)-min;
			} profit = nums.get(i)-min profit nums.get(i)-min nums.get(i) nums.get nums i min if (nums.get(i)<min) {
				min = nums.get(i);
			} nums.get(i)<min nums.get(i) nums.get nums i min {
				min = nums.get(i);
			} min = nums.get(i) min nums.get(i) nums.get nums i System.out.println(profit) System.out.println System.out System System.out profit String[] args args public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

} public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

} Main
import java.sql.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main{
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		List<Integer> nums = new ArrayList<Integer>() ;
		for (int i = 0; i < len; i++) {
			nums.add(scanner.nextInt());
		}
		
		int min = nums.get(0);
		int profit = -1000000000;
		for (int i = 1; i < len; i++) {
			if (profit<(nums.get(i)-min)) {
				profit = nums.get(i)-min;
			}
			if (nums.get(i)<min) {
				min = nums.get(i);
			}
		}
		
		System.out.println(profit);
	}

}
