import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

        System.out.println(max);
    }
} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

        System.out.println(max);
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

        System.out.println(max);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

        System.out.println(max);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = Integer.parseInt(scanner.next()); n Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int max; max int min; min int r0 = Integer.parseInt(scanner.next()); r0 Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int r1 = Integer.parseInt(scanner.next()); r1 Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner max = r1 - r0 max r1 - r0 r1 r0 min = Math.min(r1, r0) min Math.min(r1, r0) Math.min Math r1 r0 for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        } int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        } {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        } int ri = Integer.parseInt(scanner.next()); ri Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner if (ri - min > max) {
                max = ri - min;
            } ri - min > max ri - min ri min max {
                max = ri - min;
            } max = ri - min max ri - min ri min min = Math.min(ri, min) min Math.min(ri, min) Math.min Math ri min System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

        System.out.println(max);
    }
} public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

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

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.next());
        int max;
        int min;

        int r0 = Integer.parseInt(scanner.next());
        int r1 = Integer.parseInt(scanner.next());
        max = r1 - r0;
        min = Math.min(r1, r0);

        for (int i = 2; i < n; i++) {
            int ri = Integer.parseInt(scanner.next());
            if (ri - min > max) {
                max = ri - min;
            }
            min = Math.min(ri, min);
        }

        System.out.println(max);
    }
}