import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	}
}
 import java.io.FileNotFoundException; FileNotFoundException java.io import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	}
} Main public static void main(String[] args) throws FileNotFoundException {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	} main {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] r = new int[n]; r new int[n] n for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		} int t = 0; int t = 0; t 0 t < n t n t++ t++ t {
			r[t] = sc.nextInt();
		} {
			r[t] = sc.nextInt();
		} r[t] = sc.nextInt() r[t] r t sc.nextInt() sc.nextInt sc int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int ans = Integer.MIN_VALUE; ans Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		} {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		} ans = Math.max(ans, r[i] - min) ans Math.max(ans, r[i] - min) Math.max Math ans r[i] - min r[i] r i min if (min > r[i]) {
				min = r[i];
			} min > r[i] min r[i] r i {
				min = r[i];
			} min = r[i] min r[i] r i System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	}
} public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	}
} Main
import java.io.FileNotFoundException;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws FileNotFoundException {

		Scanner sc = new Scanner(System.in);
//		Scanner sc = new Scanner(new BufferedReader(new FileReader("/workspace/AOJ/src/section1/in38.txt")));

		int n = sc.nextInt();
		int[] r = new int[n];
		for (int t = 0; t < n; t++) {
			r[t] = sc.nextInt();
		}

		int min = Integer.MAX_VALUE;
		int ans = Integer.MIN_VALUE;


		for (int i = 0; i < n; i++) {
			ans = Math.max(ans, r[i] - min);
			if (min > r[i]) {
				min = r[i];
			}
		}
		System.out.println(ans);
	}
}

