import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    } try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        } {
//            while (true)
                solve(in);
        } Scanner in = new Scanner(System.in) Scanner in = new Scanner(System.in) new Scanner(System.in) solve(in) solve in String[] args args private static void solve(Scanner in) {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    } solve {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    } int n = in.nextInt(); n in.nextInt() in.nextInt in int[] R = new int[n]; R new int[n] n for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            R[i] = in.nextInt();
        } {
            R[i] = in.nextInt();
        } R[i] = in.nextInt() R[i] R i in.nextInt() in.nextInt in int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int diff = Integer.MIN_VALUE; diff Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        } {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        } if (diff < R[i] - min) {
                diff = R[i] - min;
            } diff < R[i] - min diff R[i] - min R[i] R i min {
                diff = R[i] - min;
            } diff = R[i] - min diff R[i] - min R[i] R i min if (min > R[i]) {
                min = R[i];
            } min > R[i] min R[i] R i {
                min = R[i];
            } min = R[i] min R[i] R i System.out.println(diff) System.out.println System.out System System.out diff Scanner in in public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    }
} public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
//            while (true)
                solve(in);
        }
    }

    private static void solve(Scanner in) {
        int n = in.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++) {
            R[i] = in.nextInt();
        }
        int min = Integer.MAX_VALUE;
        int diff = Integer.MIN_VALUE;
        for (int i = 0; i < n; i++) {
            if (diff < R[i] - min) {
                diff = R[i] - min;
            }
            if (min > R[i]) {
                min = R[i];
            }
        }
        System.out.println(diff);
    }
}