import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long[] a = new long[n]; a new long[n] n for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = sc.nextLong();
        } {
            a[i] = sc.nextLong();
        } a[i] = sc.nextLong() a[i] a i sc.nextLong() sc.nextLong sc long max = a[1] - a[0]; max a[1] - a[0] a[1] a 1 a[0] a 0 long min = a[0]; min a[0] a 0 for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        } {
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        } max = Math.max(max, a[i]-min) max Math.max(max, a[i]-min) Math.max Math max a[i]-min a[i] a i min min = Math.min(min, a[i]) min Math.min(min, a[i]) Math.min Math min a[i] a i 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) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0; i < n; i++){
            a[i] = sc.nextLong();
        }
        long max = a[1] - a[0];
        long min = a[0];
        for(int i = 1; i < n; i++){
            max = Math.max(max, a[i]-min);
            min = Math.min(min, a[i]);
        }
        System.out.println(max);
    }
}

