import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	}
} Main public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	} main {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	} Scanner scan = new Scanner (System.in); scan new Scanner (System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int data[] = new int[n]; data new int[n] n int minv minv maxv; maxv for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			data[i] = scan.nextInt();
		} {
			data[i] = scan.nextInt();
		} data[i] = scan.nextInt() data[i] data i scan.nextInt() scan.nextInt scan scan.close() scan.close scan maxv = data[1] - data[0] maxv data[1] - data[0] data[1] data 1 data[0] data 0 minv = data[0] minv data[0] data 0 for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		} int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		} {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		} maxv = Math.max(maxv, (data[j] - minv)) maxv Math.max(maxv, (data[j] - minv)) Math.max Math maxv (data[j] - minv) data[j] data j minv minv = Math.min(minv, data[j]) minv Math.min(minv, data[j]) Math.min Math minv data[j] data j 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 scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	}
} public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int minv , maxv;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		
		scan.close();
		
		maxv = data[1] - data[0];
		minv = data[0];
		
		for (int j = 1; j < n ; j++) {
			maxv = Math.max(maxv, (data[j] - minv));
			minv = Math.min(minv, data[j]);
		}
		
		System.out.println(maxv);
	}
}

