import java.util.Scanner;

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

        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        }

        int max = numbers[1] - numbers[0];
        int min = numbers[0];
        for (int i = 1; i < length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        }

        System.out.println(max);
    }
} import java.util.Scanner; Scanner java.util class Main {
    public static void main (String[] args) {
        final Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int[] numbers = new int[length];

        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        }

        int max = numbers[1] - numbers[0];
        int min = numbers[0];
        for (int i = 1; i < length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        }

        System.out.println(max);
    }
} Main public static void main (String[] args) {
        final Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int[] numbers = new int[length];

        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        }

        int max = numbers[1] - numbers[0];
        int min = numbers[0];
        for (int i = 1; i < length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        }

        System.out.println(max);
    } main {
        final Scanner sc = new Scanner(System.in);
        int length = sc.nextInt();
        int[] numbers = new int[length];

        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        }

        int max = numbers[1] - numbers[0];
        int min = numbers[0];
        for (int i = 1; i < length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        }

        System.out.println(max);
    } final Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int length = sc.nextInt(); length sc.nextInt() sc.nextInt sc int[] numbers = new int[length]; numbers new int[length] length for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < length i length i++ i++ i {
            numbers[i] = sc.nextInt();
        } {
            numbers[i] = sc.nextInt();
        } numbers[i] = sc.nextInt() numbers[i] numbers i sc.nextInt() sc.nextInt sc int max = numbers[1] - numbers[0]; max numbers[1] - numbers[0] numbers[1] numbers 1 numbers[0] numbers 0 int min = numbers[0]; min numbers[0] numbers 0 for (int i = 1; i < length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        } int i = 1; int i = 1; i 1 i < length i length i++ i++ i {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        } {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        } if (numbers[i] < min) {
                min = numbers[i];
                continue;
            } numbers[i] < min numbers[i] numbers i min {
                min = numbers[i];
                continue;
            } min = numbers[i] min numbers[i] numbers i continue; if (numbers[i] - min > max) {
                max = numbers[i] - min;
            } numbers[i] - min > max numbers[i] - min numbers[i] numbers i min max {
                max = numbers[i] - min;
            } max = numbers[i] - min max numbers[i] - min numbers[i] numbers i min System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.Scanner;

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

        for (int i = 0; i < length; i++) {
            numbers[i] = sc.nextInt();
        }

        int max = numbers[1] - numbers[0];
        int min = numbers[0];
        for (int i = 1; i < length; i++) {
            if (numbers[i] < min) {
                min = numbers[i];
                continue;
            }

            if (numbers[i] - min > max) {
                max = numbers[i] - min;
            }
        }

        System.out.println(max);
    }
}
