import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    }
} Main public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    } main {
        Scanner sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    } Scanner sc =new Scanner(System.in); sc new Scanner(System.in) int z = sc.nextInt(); z sc.nextInt() sc.nextInt sc int[] r = new int[z]; r new int[z] z for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < z i z i++ i++ i {
            r[i] = sc.nextInt();
        } {
            r[i] = sc.nextInt();
        } r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc int min = r[0]; min r[0] r 0 int max = r[1] - min; max r[1] - min r[1] r 1 min for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        } int i = 1; int i = 1; i 1 i < r.length i r.length r r.length i++ i++ i {
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        } {
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        } max = max > r[i] - min ? max : r[i] - min max max > r[i] - min ? max : r[i] - min max > r[i] - min max r[i] - min r[i] r i min max r[i] - min r[i] r i min min = min > r[i] ? r[i] : min min min > r[i] ? r[i] : min min > r[i] min r[i] r i r[i] r i 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 sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        int z = sc.nextInt();
        int[] r = new int[z];
        for(int i = 0; i < z; i++){
            r[i] = sc.nextInt();
        }
        int min = r[0];
        int max = r[1] - min;
        for(int i = 1; i < r.length; i++){
            max = max > r[i] - min ? max : r[i] - min;
            min = min > r[i] ? r[i] : min;
        }
        System.out.println(max);
    }
}