import java.io.File;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
} import java.io.File; File java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
} Main public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	} main {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) sc.nextInt() sc.nextInt sc int r0 = sc.nextInt(); r0 sc.nextInt() sc.nextInt sc int r1 = sc.nextInt(); r1 sc.nextInt() sc.nextInt sc int max_profit = r1 - r0; max_profit r1 - r0 r1 r0 int min_r = Math.min(r0, r1); min_r Math.min(r0, r1) Math.min Math r0 r1 while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		} sc.hasNextInt() sc.hasNextInt sc {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		} int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc max_profit = Math.max(max_profit, r - min_r) max_profit Math.max(max_profit, r - min_r) Math.max Math max_profit r - min_r r min_r min_r = Math.min(min_r, r) min_r Math.min(min_r, r) Math.min Math min_r r System.out.println(max_profit) System.out.println System.out System System.out max_profit String[] args args public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
} public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
} Main
import java.io.File;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		sc.nextInt();
		
		int r0 = sc.nextInt();
		int r1 = sc.nextInt();
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		while (sc.hasNextInt()) {
			int r = sc.nextInt();
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
}