import java.util.*;

public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}
 import java.util.*; util.* java public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

} Main void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	} run {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int maxDiff = Integer.MIN_VALUE; maxDiff Integer.MIN_VALUE Integer Integer.MIN_VALUE int minVal = scan.nextInt(); minVal scan.nextInt() scan.nextInt scan for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		} {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		} int val = scan.nextInt(); val scan.nextInt() scan.nextInt scan int diff = val - minVal; diff val - minVal val minVal if (maxDiff < diff) {
				maxDiff = diff;
			} maxDiff < diff maxDiff diff {
				maxDiff = diff;
			} maxDiff = diff maxDiff diff if (minVal > val) {
				minVal = val;
			} minVal > val minVal val {
				minVal = val;
			} minVal = val minVal val System.out.println(maxDiff) System.out.println System.out System System.out maxDiff public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	} main {
		// TODO Auto-generated method stub
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

} public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

} Main
import java.util.*;

public class Main {
	
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		
		int maxDiff = Integer.MIN_VALUE;
		int minVal = scan.nextInt();
		
		for (int i = 1; i < n; i++) {
			int val = scan.nextInt();
			int diff = val - minVal;
			if (maxDiff < diff) {
				maxDiff = diff;
			}
			if (minVal > val) {
				minVal = val;
			}
		}
		
		System.out.println(maxDiff);
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}

}

