import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	}

} Main public static void main(String[] args) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	} main {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	} int j j k; k int maxv = -1000000000; maxv -1000000000 1000000000 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int R[] = new int[n]; R new int[n] n for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next()); j=0; j=0 j 0 j<n j n j++ j++ j R[j] = Integer.parseInt(sc.next()); R[j] = Integer.parseInt(sc.next()) R[j] R j Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int minv = R[0]; minv R[0] R 0 for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				} k=1; k=1 k 1 k<n k n k++ k++ k {
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				} {
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				} maxv = Math.max(R[k]-minv,maxv) maxv Math.max(R[k]-minv,maxv) Math.max Math R[k]-minv R[k] R k minv maxv minv = Math.min(minv,R[k]) minv Math.min(minv,R[k]) Math.min Math minv R[k] R k 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) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	}

} public class Main {

	public static void main(String[] args) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int j,k;
		int maxv = -1000000000;
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int R[] = new int[n];
		for(j=0;j<n;j++)R[j] = Integer.parseInt(sc.next());
		int minv = R[0];

			for(k=1;k<n;k++){
				maxv = Math.max(R[k]-minv,maxv);
				minv = Math.min(minv,R[k]);
				}
			System.out.println(maxv);
	}

}