import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double maxProfit = -1000000000;
        double maxR = Integer.parseInt(scan.nextLine());
        double minR = maxR;
        double newR;
        double tmp = -1000000000;

        for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        }
        System.out.println((int) maxProfit);
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double maxProfit = -1000000000;
        double maxR = Integer.parseInt(scan.nextLine());
        double minR = maxR;
        double newR;
        double tmp = -1000000000;

        for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        }
        System.out.println((int) maxProfit);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double maxProfit = -1000000000;
        double maxR = Integer.parseInt(scan.nextLine());
        double minR = maxR;
        double newR;
        double tmp = -1000000000;

        for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        }
        System.out.println((int) maxProfit);
    } main {
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double maxProfit = -1000000000;
        double maxR = Integer.parseInt(scan.nextLine());
        double minR = maxR;
        double newR;
        double tmp = -1000000000;

        for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        }
        System.out.println((int) maxProfit);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = Integer.parseInt(scan.nextLine()); n Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan double maxProfit = -1000000000; maxProfit -1000000000 1000000000 double maxR = Integer.parseInt(scan.nextLine()); maxR Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan double minR = maxR; minR maxR double newR; newR double tmp = -1000000000; tmp -1000000000 1000000000 for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        } {
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        } newR = Integer.parseInt(scan.nextLine()) newR Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            } newR > minR && newR > maxR newR > minR newR minR newR > maxR newR maxR {
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            } tmp = newR - minR tmp newR - minR newR minR maxR = newR maxR newR if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            } newR <= minR newR minR {
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            } tmp = newR - minR tmp newR - minR newR minR minR = newR minR newR maxR = newR maxR newR if (tmp > maxProfit)
                maxProfit = tmp; tmp > maxProfit tmp maxProfit maxProfit = tmp maxProfit tmp System.out.println((int) maxProfit) System.out.println System.out System System.out (int) maxProfit String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);

        int n = Integer.parseInt(scan.nextLine());
        double maxProfit = -1000000000;
        double maxR = Integer.parseInt(scan.nextLine());
        double minR = maxR;
        double newR;
        double tmp = -1000000000;

        for (int i=1; i<n; i++){
            newR = Integer.parseInt(scan.nextLine());
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n", i, newR, minR, maxR, maxProfit);
            if (newR > minR && newR > maxR){
                //System.out.println("aiueo");
                tmp = newR - minR;
                maxR = newR;
            }else if (newR <= minR){
                tmp = newR - minR;
                minR = newR;
                maxR = newR;
            }
            if (tmp > maxProfit)
                maxProfit = tmp;
            //System.out.printf("%d??????????¨???????, newR:%f, minR:%f, maxR:%f, maxProfit:%f\n\n", i, newR, minR, maxR, maxProfit);
        }
        System.out.println((int) maxProfit);
    }
}