import java.util.*;

class Main {
        public static void main(String args[]) {
                try(Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                }
        }
} import java.util.*; util.* java class Main {
        public static void main(String args[]) {
                try(Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                }
        }
} Main public static void main(String args[]) {
                try(Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                }
        } main {
                try(Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                }
        } try(Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                } {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) long N = sc.nextLong(); N sc.nextLong() sc.nextLong sc long min = 1L << 60; min 1L << 60 1L 60 long ans = - (1L << 60); ans - (1L << 60) (1L << 60) 1L 60 for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        } long i = 0; long i = 0; i 0 i < N i N i++ i++ i {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        } {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        } long now = sc.nextLong(); now sc.nextLong() sc.nextLong sc ans = Math.max(ans, now - min) ans Math.max(ans, now - min) Math.max Math ans now - min now min min = Math.min(min, now) min Math.min(min, now) Math.min Math min now System.out.println(ans) System.out.println System.out System System.out ans String args[] args
import java.util.*;

class Main {
        public static void main(String args[]) {
                try(Scanner sc = new Scanner(System.in)) {
                        long N = sc.nextLong();
                        long min = 1L << 60;
                        long ans = - (1L << 60);
                        for (long i = 0; i < N; i++) {
                                long now = sc.nextLong();
                                ans = Math.max(ans, now - min);
                                min = Math.min(min, now);
                        }
                        System.out.println(ans);
                }
        }
}