import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    }
    static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    }
    static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    }
} import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    }
    static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    }
    static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    }
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] array= new int[n]; array new int[n] n for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] =  Integer.parseInt(br.readLine());
        } {
            array[i] =  Integer.parseInt(br.readLine());
        } array[i] =  Integer.parseInt(br.readLine()) array[i] array i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int minv = array[0]; minv array[0] array 0 int maxv = Integer.MIN_VALUE; maxv Integer.MIN_VALUE Integer Integer.MIN_VALUE for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        } int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        } {
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        } maxv = max(maxv, array[j] - minv) maxv max(maxv, array[j] - minv) max maxv array[j] - minv array[j] array j minv minv = min(minv, array[j]) minv min(minv, array[j]) min minv array[j] array j System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    } max {
        if (a > b){
            return a;
        }else{
            return b;
        }
    } if (a > b){
            return a;
        }else{
            return b;
        } a > b a b {
            return a;
        } return a; a {
            return b;
        } return b; b int a a int b b static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    } min {
        if (a > b){
            return b;
        }else{
            return a;
        }
    } if (a > b){
            return b;
        }else{
            return a;
        } a > b a b {
            return b;
        } return b; b {
            return a;
        } return a; a int a a int b b public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    }
    static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    }
    static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    }
} public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    }
    static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    }
    static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    }
} Main
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] array= new int[n];
        for (int i = 0; i < n; i++){
            array[i] =  Integer.parseInt(br.readLine());
        }
        int minv = array[0];
        int maxv = Integer.MIN_VALUE;
        for (int j = 1; j < n; j++){
            maxv = max(maxv, array[j] - minv);
            minv = min(minv, array[j]);
        }
        System.out.println(maxv);
    }
    static int max(int a, int b){
        if (a > b){
            return a;
        }else{
            return b;
        }
    }
    static int min(int a, int b){
        if (a > b){
            return b;
        }else{
            return a;
        }
    }
}