import java.util.Scanner;

public class Main {
    private static Scanner sc=new Scanner(System.in);
    private static final int MINF=-1000000000;
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    private static Scanner sc=new Scanner(System.in);
    private static final int MINF=-1000000000;
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    }
} Main private static Scanner sc=new Scanner(System.in); sc new Scanner(System.in) private static final int MINF=-1000000000; MINF -1000000000 1000000000 public static void main(String[] args){
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    } main {
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    } int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] r=new int[n]; r new int[n] n for(int i=0;i<n;i++) r[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i r[i]=sc.nextInt(); r[i]=sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int max=MINF; max MINF int maxp=MINF; maxp MINF for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        } int i=n-2; int i=n-2; i n-2 n 2 i>=0 i 0 i-- i-- i {
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        } {
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        } max=Math.max(max,r[i+1]) max Math.max(max,r[i+1]) Math.max Math max r[i+1] r i+1 i 1 maxp=Math.max(maxp,max-r[i]) maxp Math.max(maxp,max-r[i]) Math.max Math maxp max-r[i] max r[i] r i System.out.println(maxp) System.out.println System.out System System.out maxp String[] args args public class Main {
    private static Scanner sc=new Scanner(System.in);
    private static final int MINF=-1000000000;
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    }
} public class Main {
    private static Scanner sc=new Scanner(System.in);
    private static final int MINF=-1000000000;
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    }
} Main
import java.util.Scanner;

public class Main {
    private static Scanner sc=new Scanner(System.in);
    private static final int MINF=-1000000000;
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] r=new int[n];
        for(int i=0;i<n;i++) r[i]=sc.nextInt();
        int max=MINF;
        int maxp=MINF;
        for(int i=n-2;i>=0;i--){
            max=Math.max(max,r[i+1]);
            maxp=Math.max(maxp,max-r[i]);
        }
        System.out.println(maxp);
    }
}