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

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	}

}
 import java.util.ArrayList; ArrayList java.util 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 maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	}

} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int maxv = -2000000000; maxv -2000000000 2000000000 ArrayList<Integer> numbers = new ArrayList<Integer>(); numbers new ArrayList<Integer>() for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		} int i =0; int i =0; i 0 i<N i N i++ i++ i {
			numbers.add(sc.nextInt());
		} {
			numbers.add(sc.nextInt());
		} numbers.add(sc.nextInt()) numbers.add numbers sc.nextInt() sc.nextInt sc int minv = numbers.get(0); minv numbers.get(0) numbers.get numbers 0 for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		} int i =1; int i =1; i 1 i<N i N i++ i++ i {
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		} {
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		} maxv = Math.max(maxv, numbers.get(i)-minv) maxv Math.max(maxv, numbers.get(i)-minv) Math.max Math maxv numbers.get(i)-minv numbers.get(i) numbers.get numbers i minv minv = Math.min(minv, numbers.get(i)) minv Math.min(minv, numbers.get(i)) Math.min Math minv numbers.get(i) numbers.get numbers i 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){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	}

} public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	}

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

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int maxv = -2000000000;
		ArrayList<Integer> numbers = new ArrayList<Integer>();
		for(int i =0;i<N;i++){
			numbers.add(sc.nextInt());
		}
		int minv = numbers.get(0);
		for(int i =1;i<N;i++){
			maxv = Math.max(maxv, numbers.get(i)-minv);
			minv = Math.min(minv, numbers.get(i));
		}
		System.out.println(maxv);

	}

}

