import java.util.*;

class Main {

    void solve() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		}
		System.out.println(max);
	}

    public static void main(String[] args) {
        new Main().solve();
    }
} import java.util.*; util.* java class Main {

    void solve() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		}
		System.out.println(max);
	}

    public static void main(String[] args) {
        new Main().solve();
    }
} Main void solve() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		}
		System.out.println(max);
	} solve {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		}
		System.out.println(max);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int max = Integer.MIN_VALUE max Integer.MIN_VALUE Integer Integer.MIN_VALUE min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 0; i < n; i++){
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		} {
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		} int r = in.nextInt(); r in.nextInt() in.nextInt in max = Math.max(max, r - min) max Math.max(max, r - min) Math.max Math max r - min r min min = Math.min(min, r) min Math.min(min, r) Math.min Math min r System.out.println(max) System.out.println System.out System System.out max public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args
import java.util.*;

class Main {

    void solve() {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int max = Integer.MIN_VALUE, min = Integer.MAX_VALUE;
		for(int i = 0; i < n; i++){
			int r = in.nextInt();
			max = Math.max(max, r - min);
			min = Math.min(min, r);
		}
		System.out.println(max);
	}

    public static void main(String[] args) {
        new Main().solve();
    }
}