import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    }

} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    }

} Main public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    } main {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] arr = new int[n]; arr new int[n] n for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arr[i] = scan.nextInt();
        } {
            arr[i] = scan.nextInt();
        } arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan int answer = arr[1] - arr[0]; answer arr[1] - arr[0] arr[1] arr 1 arr[0] arr 0 int min = arr[0]; min arr[0] arr 0 for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        } int i = 1; int i = 1; i 1 i < arr.length i arr.length arr arr.length i++ i++ i {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        } {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        } if (arr[i] - min > answer) {
                answer = arr[i] - min;
            } arr[i] - min > answer arr[i] - min arr[i] arr i min answer {
                answer = arr[i] - min;
            } answer = arr[i] - min answer arr[i] - min arr[i] arr i min min = Math.min(min, arr[i]) min Math.min(min, arr[i]) Math.min Math min arr[i] arr i System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main{

    public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    }

} public class Main{

    public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    }

} Main
import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        // ?????\??°???
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scan.nextInt();
        }

        int answer = arr[1] - arr[0];
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] - min > answer) {
                answer = arr[i] - min;
            }
            min = Math.min(min, arr[i]);
        }
        System.out.println(answer);

    }

}