import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    }
} Main public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long min = sc.nextInt(); min sc.nextInt() sc.nextInt sc long ret = -1000000001; ret -1000000001 1000000001 for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        } int i = 1; int i = 1; i 1 i<n i n i++ i++ i {
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        } {
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        } long r = sc.nextInt(); r sc.nextInt() sc.nextInt sc if (r - min > ret) ret = r - min; r - min > ret r - min r min ret ret = r - min ret r - min r min if (r < min) min = r; r < min r min min = r min r System.out.println(ret) System.out.println System.out System System.out ret String args[] args public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    }
} public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        long min = sc.nextInt();
        long ret = -1000000001;

        for (int i = 1; i<n; i++){
            long r = sc.nextInt();
            if (r - min > ret) ret = r - min;
            if (r < min) min = r;
        }
        System.out.println(ret);
    }
}