import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	}

} import java.util.Arrays; Arrays java.util 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 R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int R[] = new int[n]; R new int[n] n for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			R[i]  = scan.nextInt();
		} {
			R[i]  = scan.nextInt();
		} R[i]  = scan.nextInt() R[i] R i scan.nextInt() scan.nextInt scan int ans = Integer.MIN_VALUE; ans Integer.MIN_VALUE Integer Integer.MIN_VALUE int max = R[0]; max R[0] R 0 for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		} {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		} if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			} max == R[i] max R[i] R i {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			} int array[] = new int[n - i - 1]; array new int[n - i - 1] n - i - 1 n - i - 1 n i 1 System.arraycopy(R, i + 1, array, 0, n - i - 1) System.arraycopy System R i + 1 i 1 array 0 n - i - 1 n - i - 1 n i 1 Arrays.sort(array) Arrays.sort Arrays array max = array[array.length-1] max array[array.length-1] array array.length-1 array.length array array.length 1 ans = Math.max(ans, max - R[i]) ans Math.max(ans, max - R[i]) Math.max Math ans max - R[i] max R[i] R i System.out.println(ans) System.out.println System.out System System.out ans scan.close() scan.close scan String[] args args public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	}

} Main
import java.util.Arrays;
import java.util.Scanner;


public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int R[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			R[i]  = scan.nextInt();
		}

		int ans = Integer.MIN_VALUE;
		int max = R[0];
		
		for (int i = 0; i < n - 1; i++) {
			if (max == R[i]) {
				int array[] = new int[n - i - 1];
				System.arraycopy(R, i + 1, array, 0, n - i - 1);
				Arrays.sort(array);
				max = array[array.length-1];
			}
			ans = Math.max(ans, max - R[i]);
		}

		System.out.println(ans);
		scan.close();
	}

}