import java.util.Scanner;

public class Main {


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

		int n = scan.nextInt();

		int[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	}

} 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[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	}

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

		int n = scan.nextInt();

		int[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	} main {
		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();

		int[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] nAry = new int[n]; nAry new int[n] n for(int i = 0; i < n ; i++){
			nAry[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			nAry[i] = scan.nextInt();
		} {
			nAry[i] = scan.nextInt();
		} nAry[i] = scan.nextInt() nAry[i] nAry i scan.nextInt() scan.nextInt scan int maxBenefit = Integer.MIN_VALUE; maxBenefit Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = nAry[0]; min nAry[0] nAry 0 int tmpBenefit; tmpBenefit for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		} {

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		} tmpBenefit = nAry[i] - min tmpBenefit nAry[i] - min nAry[i] nAry i min if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			} maxBenefit < tmpBenefit maxBenefit tmpBenefit {
				maxBenefit = tmpBenefit;
			} maxBenefit = tmpBenefit maxBenefit tmpBenefit if(min > nAry[i]){
				min = nAry[i];
			} min > nAry[i] min nAry[i] nAry i {
				min = nAry[i];
			} min = nAry[i] min nAry[i] nAry i System.out.println(maxBenefit) System.out.println System.out System System.out maxBenefit String[] args args public class Main {


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

		int n = scan.nextInt();

		int[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	}

} public class Main {


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

		int n = scan.nextInt();

		int[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	}

} 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[] nAry = new int[n];

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

		int maxBenefit = Integer.MIN_VALUE;
		int min = nAry[0];
		int tmpBenefit;

		for(int i = 1; i < n ; i++){

			tmpBenefit = nAry[i] - min;

			if(maxBenefit < tmpBenefit){
				maxBenefit = tmpBenefit;
			}

			if(min > nAry[i]){
				min = nAry[i];
			}
		}

		System.out.println(maxBenefit);
	}

}