import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n; n n = sc.nextInt() n sc.nextInt() sc.nextInt sc int r[] = new int[n]; r new int[n] n for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            r[i] = sc.nextInt();
        } {
            r[i] = sc.nextInt();
        } r[i] = sc.nextInt() r[i] r i sc.nextInt() sc.nextInt sc long max = -1000000010; max -1000000010 1000000010 long min = r[0]; min r[0] r 0 for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        } {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        } if (r[i] - min > max)
                max = r[i] - min; r[i] - min > max r[i] - min r[i] r i min max max = r[i] - min max r[i] - min r[i] r i min if (r[i] < min)
                min = r[i]; r[i] < min r[i] r i min min = r[i] min r[i] r i System.out.println(max) System.out.println System.out System System.out max sc.close() sc.close sc String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n;
        n = sc.nextInt();
        int r[] = new int[n];
        for (int i = 0; i < n; i++) {
            r[i] = sc.nextInt();
        }
        long max = -1000000010;
        long min = r[0];
        for (int i = 1; i < n; i++) {
            if (r[i] - min > max)
                max = r[i] - min;
            if (r[i] < min)
                min = r[i];
        }
        System.out.println(max);
        sc.close();
    }
}
