import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] r = new int[n];
        for(int x=0; x < n; x++){
            r[x] = Integer.parseInt(sc.nextLine());
        }
        int maxv = -2000000000;
        int minv = r[0];

        for(int i = 1; i < n; i++){
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        }
        System.out.println(maxv);

    }
} import java.util.*; util.* java class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] r = new int[n];
        for(int x=0; x < n; x++){
            r[x] = Integer.parseInt(sc.nextLine());
        }
        int maxv = -2000000000;
        int minv = r[0];

        for(int i = 1; i < n; i++){
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        }
        System.out.println(maxv);

    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] r = new int[n];
        for(int x=0; x < n; x++){
            r[x] = Integer.parseInt(sc.nextLine());
        }
        int maxv = -2000000000;
        int minv = r[0];

        for(int i = 1; i < n; i++){
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        }
        System.out.println(maxv);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] r = new int[n];
        for(int x=0; x < n; x++){
            r[x] = Integer.parseInt(sc.nextLine());
        }
        int maxv = -2000000000;
        int minv = r[0];

        for(int i = 1; i < n; i++){
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        }
        System.out.println(maxv);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] r = new int[n]; r new int[n] n for(int x=0; x < n; x++){
            r[x] = Integer.parseInt(sc.nextLine());
        } int x=0; int x=0; x 0 x < n x n x++ x++ x {
            r[x] = Integer.parseInt(sc.nextLine());
        } {
            r[x] = Integer.parseInt(sc.nextLine());
        } r[x] = Integer.parseInt(sc.nextLine()) r[x] r x Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int maxv = -2000000000; maxv -2000000000 2000000000 int minv = r[0]; minv r[0] r 0 for(int i = 1; i < n; i++){
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        } {
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        } maxv = Math.max(maxv, r[i] - minv) maxv Math.max(maxv, r[i] - minv) Math.max Math maxv r[i] - minv r[i] r i minv minv = Math.min(minv, r[i]) minv Math.min(minv, r[i]) Math.min Math minv r[i] r i System.out.println(maxv) System.out.println System.out System System.out maxv String args[] args
import java.util.*;

class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        int[] r = new int[n];
        for(int x=0; x < n; x++){
            r[x] = Integer.parseInt(sc.nextLine());
        }
        int maxv = -2000000000;
        int minv = r[0];

        for(int i = 1; i < n; i++){
            maxv = Math.max(maxv, r[i] - minv);
            minv = Math.min(minv, r[i]);
        }
        System.out.println(maxv);

    }
}