import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line1 = sc.nextLine(); line1 sc.nextLine() sc.nextLine sc int n = Integer.parseInt(line1); n Integer.parseInt(line1) Integer.parseInt Integer line1 String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc int R0 = Integer.parseInt(line2); R0 Integer.parseInt(line2) Integer.parseInt Integer line2 String line3 = sc.nextLine(); line3 sc.nextLine() sc.nextLine sc int R1 = Integer.parseInt(line3); R1 Integer.parseInt(line3) Integer.parseInt Integer line3 int min = Math.min(R0, R1); min Math.min(R0, R1) Math.min Math R0 R1 int answer = R1 - R0; answer R1 - R0 R1 R0 for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		} int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		} {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		} String next = sc.nextLine(); next sc.nextLine() sc.nextLine sc int R = Integer.parseInt(next); R Integer.parseInt(next) Integer.parseInt Integer next answer = Math.max(answer, R-min) answer Math.max(answer, R-min) Math.max Math answer R-min R min min = Math.min(min, R) min Math.min(min, R) Math.min Math min R System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		int R0 = Integer.parseInt(line2);
		
		String line3 = sc.nextLine();
		int R1 = Integer.parseInt(line3);
		
		int min = Math.min(R0, R1);
		int answer = R1 - R0;		
		
		for (int i = 2; i < n; i++) {
			String next = sc.nextLine();
			int R = Integer.parseInt(next);
			
			answer = Math.max(answer, R-min);
			min = Math.min(min, R);
		}
		
		System.out.println(answer);

	}

}