import java.io.*;

public class Main {
	public static void main(String[] args) {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	}
}
		 import java.io.*; io.* java public class Main {
	public static void main(String[] args) {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	}
} Main public static void main(String[] args) {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	} main {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	} int MAX = 200000; MAX 200000 int n; n int[] R; R R = new int[MAX] R new int[MAX] MAX BufferedReader reader = new BufferedReader (new InputStreamReader(System.in)); reader new BufferedReader (new InputStreamReader(System.in)) try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		} catch (IOException e) {
			System.out.println(e);
		} IOException e {
			System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		} NumberFormatException e {
			System.out.println("??°????????\?????????????????????");
		} System.out.println("??°????????\?????????????????????") System.out.println System.out System System.out "??°????????\?????????????????????" {
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} String line = reader.readLine(); line reader.readLine() reader.readLine reader n = Integer.parseInt(line) n Integer.parseInt(line) Integer.parseInt Integer line for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			} {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			} line =reader.readLine() line reader.readLine() reader.readLine reader R[i] = Integer.parseInt(line) R[i] R i Integer.parseInt(line) Integer.parseInt Integer line int maxv = -2000000000; maxv -2000000000 2000000000 int minv = R[0]; minv R[0] R 0 for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			} {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			} maxv = Math.max(maxv, R[i] -minv) maxv Math.max(maxv, R[i] -minv) Math.max Math maxv R[i] -minv R[i] R i minv minv = Math.min(minv, R[i]) minv Math.min(minv, R[i]) Math.min Math minv R[i] R i 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) {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	}
} public class Main {
	public static void main(String[] args) {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	}
} Main
import java.io.*;

public class Main {
	public static void main(String[] args) {
		int MAX = 200000;
		int n;
		int[] R;
		
		R = new int[MAX];
		
		BufferedReader reader = new BufferedReader (new InputStreamReader(System.in));
		try{
			String line = reader.readLine();
			
			n = Integer.parseInt(line);
			for(int i = 0; i < n; i++ ) {
				line =reader.readLine();
				R[i] = Integer.parseInt(line);
			}
			
			int maxv = -2000000000;
			int minv = R[0];
			
			for ( int i = 1; i < n ; i++) {
				maxv = Math.max(maxv, R[i] -minv);
				minv = Math.min(minv, R[i]);
			}
			
			System.out.println(maxv);
			
		} catch (IOException e) {
			System.out.println(e);
		} catch (NumberFormatException e) {
			System.out.println("??°????????\?????????????????????");
		}
	}
}
		