import java.util.Scanner;

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

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

        System.out.println(cal(array));
    }

    public static int cal(int[] array){
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];

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

        System.out.println(cal(array));
    }

    public static int cal(int[] array){
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];

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

        System.out.println(cal(array));
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];

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

        System.out.println(cal(array));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n for(int i=0; i<n; i++){
            array[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc System.out.println(cal(array)) System.out.println System.out System System.out cal(array) cal array String[] args args public static int cal(int[] array){
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    } cal {
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    } int ans = -1000000000; ans -1000000000 1000000000 int min = array[0]; min array[0] array 0 for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        } int i=0; int i=0; i 0 i < array.length-1 i array.length-1 array.length array array.length 1 i++ i++ i {
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        } {
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        } if(array[i] < min) min = array[i]; array[i] < min array[i] array i min min = array[i] min array[i] array i int def = array[i+1] - min; def array[i+1] - min array[i+1] array i+1 i 1 min if(ans < def) ans = def; ans < def ans def ans = def ans def return ans; ans int[] array array public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];

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

        System.out.println(cal(array));
    }

    public static int cal(int[] array){
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] array = new int[n];

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

        System.out.println(cal(array));
    }

    public static int cal(int[] array){
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    }
} Main
import java.util.Scanner;

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

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

        System.out.println(cal(array));
    }

    public static int cal(int[] array){
        int ans = -1000000000;
        int min = array[0];

        for(int i=0; i < array.length-1; i++){
            if(array[i] < min) min = array[i];
            int def = array[i+1] - min;
            if(ans < def) ans = def;
        }
        return ans;
    }
}