import java.io.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		// Scanner sc = new Scanner(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.FileReader; FileReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args) throws Exception {
		// Scanner sc = new Scanner(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			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(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			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(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int r0 = Integer.parseInt(br.readLine()); r0 Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int r1 = Integer.parseInt(br.readLine()); r1 Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br 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 for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		} int i = 2; int i = 2; i 2 i < N i N i++ i++ i {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		} {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		} int r = Integer.parseInt(br.readLine()); r Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br 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(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			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(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			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.BufferedReader;
import java.io.FileReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws Exception {
		// Scanner sc = new Scanner(new System.in);
		// Scanner sc = new Scanner(new File("in1.txt"));
		// Scanner sc = new Scanner(new File("in2.txt"));
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		// BufferedReader br = new BufferedReader(new FileReader("in1.txt"));
		int N = Integer.parseInt(br.readLine());
		// sc.nextInt();
		
		// int r0 = sc.nextInt();
		// int r1 = sc.nextInt();
		int r0 = Integer.parseInt(br.readLine());
		int r1 = Integer.parseInt(br.readLine());
		int max_profit = r1 - r0;
		int min_r = Math.min(r0, r1);
		// while (sc.hasNextInt()) {
		for (int i = 2; i < N; i++) {
			// int r = sc.nextInt();
			int r = Integer.parseInt(br.readLine());
			max_profit = Math.max(max_profit, r - min_r);
			min_r = Math.min(min_r, r);
		}
		System.out.println(max_profit);
	}
}