import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	} main {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] data = new int[n]; data new int[n] n for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    		data[i] = sc.nextInt();
    	} {
    		data[i] = sc.nextInt();
    	} data[i] = sc.nextInt() data[i] data i sc.nextInt() sc.nextInt sc int[] dataMax = new int[n]; dataMax new int[n] n for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	} int i = n - 1; int i = n - 1; i n - 1 n 1 i >= 0 i 0 i-- i-- i {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	} {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	} if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		} i == n - 1 i n - 1 n 1 {
    			dataMax[i] = data[i];
    		} dataMax[i] = data[i] dataMax[i] dataMax i data[i] data i {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		} dataMax[i] = Math.max(dataMax[i + 1], data[i]) dataMax[i] dataMax i Math.max(dataMax[i + 1], data[i]) Math.max Math dataMax[i + 1] dataMax i + 1 i 1 data[i] data i int max_profit = data[1] - data[0]; max_profit data[1] - data[0] data[1] data 1 data[0] data 0 for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	} {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	} max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]) max_profit Math.max(max_profit, dataMax[i + 1] - data[i]) Math.max Math max_profit dataMax[i + 1] - data[i] dataMax[i + 1] dataMax i + 1 i 1 data[i] data i System.out.println(max_profit) System.out.println System.out System System.out max_profit sc.close() sc.close sc String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];

    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	// i以降の最大値を保持
    	int[] dataMax = new int[n];
    	for (int i = n - 1; i >= 0; i--) {
    		if (i == n - 1) {
    			dataMax[i] = data[i];
    		} else {
    			dataMax[i] = Math.max(dataMax[i + 1], data[i]);
    		}
    	}

    	int max_profit = data[1] - data[0];
    	for (int i = 0; i < n - 1; i++) {
//    		if (i == 0 || data[i - 1] > data[i]) {
    			max_profit = Math.max(max_profit, dataMax[i + 1] - data[i]);
//    		}
    	}
		
    	System.out.println(max_profit);
    	
        sc.close();
	}
}