import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        long minR,maxR;
        minR = (long)Math.pow(10,9)+1;
        maxR = -1;
        n = input.nextInt();
        long[] min = new long[n];
        long[] max = new long[n];
        long[] R = new long[n];
        for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        }
        for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        }
        long ans;
        ans = -(long)Math.pow(10,9)-1;
        for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        }
        System.out.println(ans);
    }
} import java.util.*; util.* java import java.util.stream.*; stream.* java.util class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        long minR,maxR;
        minR = (long)Math.pow(10,9)+1;
        maxR = -1;
        n = input.nextInt();
        long[] min = new long[n];
        long[] max = new long[n];
        long[] R = new long[n];
        for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        }
        for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        }
        long ans;
        ans = -(long)Math.pow(10,9)-1;
        for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        long minR,maxR;
        minR = (long)Math.pow(10,9)+1;
        maxR = -1;
        n = input.nextInt();
        long[] min = new long[n];
        long[] max = new long[n];
        long[] R = new long[n];
        for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        }
        for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        }
        long ans;
        ans = -(long)Math.pow(10,9)-1;
        for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        }
        System.out.println(ans);
    } main {
        Scanner input = new Scanner(System.in);
        int n;
        long minR,maxR;
        minR = (long)Math.pow(10,9)+1;
        maxR = -1;
        n = input.nextInt();
        long[] min = new long[n];
        long[] max = new long[n];
        long[] R = new long[n];
        for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        }
        for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        }
        long ans;
        ans = -(long)Math.pow(10,9)-1;
        for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        }
        System.out.println(ans);
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n; n long minR minR maxR; maxR minR = (long)Math.pow(10,9)+1 minR (long)Math.pow(10,9)+1 (long)Math.pow(10,9) Math.pow Math 10 9 1 maxR = -1 maxR -1 1 n = input.nextInt() n input.nextInt() input.nextInt input long[] min = new long[n]; min new long[n] n long[] max = new long[n]; max new long[n] n long[] R = new long[n]; R new long[n] n for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        } {
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        } R[i] = input.nextLong() R[i] R i input.nextLong() input.nextLong input minR = Math.min(R[i],minR) minR Math.min(R[i],minR) Math.min Math R[i] R i minR min[i] = minR min[i] min i minR for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        } int i = n-1; int i = n-1; i n-1 n 1 i > -1 i -1 1 i-- i-- i {
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        } {
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        } maxR = Math.max(R[i],maxR) maxR Math.max(R[i],maxR) Math.max Math R[i] R i maxR max[i] = maxR max[i] max i maxR long ans; ans ans = -(long)Math.pow(10,9)-1 ans -(long)Math.pow(10,9)-1 -(long)Math.pow(10,9) (long)Math.pow(10,9) Math.pow Math 10 9 1 for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
            ans = Math.max(ans,max[i+1]-min[i]);
        } {
            ans = Math.max(ans,max[i+1]-min[i]);
        } ans = Math.max(ans,max[i+1]-min[i]) ans Math.max(ans,max[i+1]-min[i]) Math.max Math ans max[i+1]-min[i] max[i+1] max i+1 i 1 min[i] min i System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.util.*;
import java.util.stream.*;
class Main {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        long minR,maxR;
        minR = (long)Math.pow(10,9)+1;
        maxR = -1;
        n = input.nextInt();
        long[] min = new long[n];
        long[] max = new long[n];
        long[] R = new long[n];
        for (int i = 0; i < n; i++){
            R[i] = input.nextLong();
            minR = Math.min(R[i],minR);
            min[i] = minR;
        }
        for (int i = n-1; i > -1; i--){
            maxR = Math.max(R[i],maxR);
            max[i] = maxR;
        }
        long ans;
        ans = -(long)Math.pow(10,9)-1;
        for (int i = 0; i < n-1; i++){
            ans = Math.max(ans,max[i+1]-min[i]);
        }
        System.out.println(ans);
    }
}
