

import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i< n ; i++){
            arr[i] = scanner.nextInt();
        }
        int maxMinus = arr[1] - arr[0];
        int minValue = arr[0];
        for (int i= 1; i< n ; i++){
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        }
        System.out.println(maxMinus);
    }

}
 import java.util.Scanner; Scanner java.util class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i< n ; i++){
            arr[i] = scanner.nextInt();
        }
        int maxMinus = arr[1] - arr[0];
        int minValue = arr[0];
        for (int i= 1; i< n ; i++){
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        }
        System.out.println(maxMinus);
    }

} Main public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i< n ; i++){
            arr[i] = scanner.nextInt();
        }
        int maxMinus = arr[1] - arr[0];
        int minValue = arr[0];
        for (int i= 1; i< n ; i++){
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        }
        System.out.println(maxMinus);
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i< n ; i++){
            arr[i] = scanner.nextInt();
        }
        int maxMinus = arr[1] - arr[0];
        int minValue = arr[0];
        for (int i= 1; i< n ; i++){
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        }
        System.out.println(maxMinus);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] arr = new int[n]; arr new int[n] n for (int i = 0; i< n ; i++){
            arr[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i< n i n i++ i++ i {
            arr[i] = scanner.nextInt();
        } {
            arr[i] = scanner.nextInt();
        } arr[i] = scanner.nextInt() arr[i] arr i scanner.nextInt() scanner.nextInt scanner int maxMinus = arr[1] - arr[0]; maxMinus arr[1] - arr[0] arr[1] arr 1 arr[0] arr 0 int minValue = arr[0]; minValue arr[0] arr 0 for (int i= 1; i< n ; i++){
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        } int i= 1; int i= 1; i 1 i< n i n i++ i++ i {
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        } {
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        } maxMinus = Math.max(maxMinus, arr[i] - minValue) maxMinus Math.max(maxMinus, arr[i] - minValue) Math.max Math maxMinus arr[i] - minValue arr[i] arr i minValue minValue = Math.min(minValue, arr[i]) minValue Math.min(minValue, arr[i]) Math.min Math minValue arr[i] arr i System.out.println(maxMinus) System.out.println System.out System System.out maxMinus String[] args args


import java.util.Scanner;

class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i< n ; i++){
            arr[i] = scanner.nextInt();
        }
        int maxMinus = arr[1] - arr[0];
        int minValue = arr[0];
        for (int i= 1; i< n ; i++){
           maxMinus = Math.max(maxMinus, arr[i] - minValue);
           minValue = Math.min(minValue, arr[i]);
        }
        System.out.println(maxMinus);
    }

}

