import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int maxValue = -1999999999; maxValue -1999999999 1999999999 int min = sc.nextInt(); min sc.nextInt() sc.nextInt sc for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		} {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		} int nowNum = sc.nextInt(); nowNum sc.nextInt() sc.nextInt sc int maxValueCandidate = nowNum - min; maxValueCandidate nowNum - min nowNum min if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			} maxValue < maxValueCandidate maxValue maxValueCandidate {
				maxValue = maxValueCandidate;
			} maxValue = maxValueCandidate maxValue maxValueCandidate if(min > nowNum) {
				min = nowNum;
			} min > nowNum min nowNum {
				min = nowNum;
			} min = nowNum min nowNum sc.close() sc.close sc System.out.println(maxValue) System.out.println System.out System System.out maxValue String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int maxValue = -1999999999;
		int min = sc.nextInt();
		for(int i = 1; i < n; i++) {
			int nowNum = sc.nextInt();
			int maxValueCandidate = nowNum - min;
			if (maxValue < maxValueCandidate) {
				maxValue = maxValueCandidate;
			}
			if(min > nowNum) {
				min = nowNum;
			}
		}
		sc.close();
		System.out.println(maxValue);
	}
}