import java.util.Scanner;

public class Main {
    private static final int MAXSIZE = 200000;

    public static void main(String[] args) {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    private static final int MAXSIZE = 200000;

    public static void main(String[] args) {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    }
} Main private static final int MAXSIZE = 200000; MAXSIZE 200000 public static void main(String[] args) {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    } main {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    } int[] R = new int[MAXSIZE]; R new int[MAXSIZE] MAXSIZE Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int rLength = sc.nextInt(); rLength sc.nextInt() sc.nextInt sc for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        } int idx = 0; int idx = 0; idx 0 idx < rLength idx rLength idx++ idx++ idx {
            R[idx] = sc.nextInt();
        } {
            R[idx] = sc.nextInt();
        } R[idx] = sc.nextInt() R[idx] R idx sc.nextInt() sc.nextInt sc int res = Integer.MIN_VALUE; res Integer.MIN_VALUE Integer Integer.MIN_VALUE int currMin = R[0]; currMin R[0] R 0 for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        } int idx = 1; int idx = 1; idx 1 idx < rLength idx rLength idx++ idx++ idx {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        } {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        } res = Math.max(res, R[idx] - currMin) res Math.max(res, R[idx] - currMin) Math.max Math res R[idx] - currMin R[idx] R idx currMin currMin = Math.min(currMin, R[idx]) currMin Math.min(currMin, R[idx]) Math.min Math currMin R[idx] R idx System.out.println(res) System.out.println System.out System System.out res String[] args args public class Main {
    private static final int MAXSIZE = 200000;

    public static void main(String[] args) {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    }
} public class Main {
    private static final int MAXSIZE = 200000;

    public static void main(String[] args) {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    }
} Main
import java.util.Scanner;

public class Main {
    private static final int MAXSIZE = 200000;

    public static void main(String[] args) {
        int[] R = new int[MAXSIZE];

        Scanner sc = new Scanner(System.in);
        int rLength = sc.nextInt();

        for (int idx = 0; idx < rLength; idx++) {
            R[idx] = sc.nextInt();
        }

        int res = Integer.MIN_VALUE;
        int currMin = R[0];
        for (int idx = 1; idx < rLength; idx++) {
            res = Math.max(res, R[idx] - currMin);
            currMin = Math.min(currMin, R[idx]);
        }

        System.out.println(res);
    }
}
