import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	}
}
 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 r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int r[] = new int[n]; r new int[n] n int maxv = -999999999; maxv -999999999 999999999 for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < r.length i r.length r r.length i++ i++ i {
			r[i] = sc.nextInt();
		} {
			r[i] = sc.nextInt();
		} r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int minv = r[0]; minv r[0] r 0 for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		} {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		} maxv = r[i] - minv > maxv ? r[i] - minv : maxv maxv r[i] - minv > maxv ? r[i] - minv : maxv r[i] - minv > maxv r[i] - minv r[i] r i minv maxv r[i] - minv r[i] r i minv maxv minv = minv > r[i] ? r[i] : minv minv minv > r[i] ? r[i] : minv minv > r[i] minv r[i] r i r[i] r i minv System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	}
} 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 r[] = new int[n];
		int maxv = -999999999;
		for (int i = 0; i < r.length; i++) {
			r[i] = sc.nextInt();
		}
		int minv = r[0];
		for (int i = 1; i < n; i++) {
			maxv = r[i] - minv > maxv ? r[i] - minv : maxv;
			minv = minv > r[i] ? r[i] : minv;
		}
		System.out.println(maxv);
	}
}

