import java.util.Scanner;

/**
 * Created by hwzheng on 2017/3/26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    }

    public static int maxProfit(int[] R){
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    }

    public static int maxProfit(int[] R){
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    } main {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] R = new int[n]; R new int[n] n for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            R[i] = scanner.nextInt();
        } {
            R[i] = scanner.nextInt();
        } R[i] = scanner.nextInt() R[i] R i scanner.nextInt() scanner.nextInt scanner System.out.println(maxProfit(R)) System.out.println System.out System System.out maxProfit(R) maxProfit R String[] args args public static int maxProfit(int[] R){
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    } maxProfit {
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    } int maxv = R[1] - R[0]; maxv R[1] - R[0] R[1] R 1 R[0] R 0 int minv = R[0]; minv R[0] R 0 for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        } int i = 1; int i = 1; i 1 i < R.length i R.length R R.length i++ i++ i {
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        } {
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        } maxv = Math.max(R[i]-minv,maxv) maxv Math.max(R[i]-minv,maxv) Math.max Math R[i]-minv R[i] R i minv maxv minv = Math.min(R[i],minv) minv Math.min(R[i],minv) Math.min Math R[i] R i minv return maxv; maxv int[] R R public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    }

    public static int maxProfit(int[] R){
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    }

    public static int maxProfit(int[] R){
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    }
} Main
import java.util.Scanner;

/**
 * Created by hwzheng on 2017/3/26.
 */
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] R = new int[n];
        for (int i = 0; i < n; i++){
            R[i] = scanner.nextInt();
        }
        System.out.println(maxProfit(R));
    }

    public static int maxProfit(int[] R){
        int maxv = R[1] - R[0];
        int minv = R[0];
        for (int i = 1; i < R.length; i++){
            maxv = Math.max(R[i]-minv,maxv);
            minv = Math.min(R[i],minv);
        }
        return maxv;
    }
}