import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    } main {
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int iniNum iniNum RiNum; RiNum iniNum = scan.nextInt() iniNum scan.nextInt() scan.nextInt scan int buyPrice=1000000001 buyPrice 1000000001 maxProfit=-1000000001; maxProfit -1000000001 1000000001 for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        } int i=0; int i=0; i 0 i<iniNum i iniNum i++ i++ i {
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        } {
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        } RiNum = scan.nextInt() RiNum scan.nextInt() scan.nextInt scan maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice) maxProfit i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice) i==0 i 0 -1000000000 1000000000 Math.max(maxProfit,RiNum-buyPrice) Math.max Math maxProfit RiNum-buyPrice RiNum buyPrice buyPrice=Math.min(buyPrice,RiNum) buyPrice Math.min(buyPrice,RiNum) Math.min Math buyPrice RiNum System.out.println(maxProfit) System.out.println System.out System System.out maxProfit String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    }
} Main
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int iniNum, RiNum;
        iniNum = scan.nextInt();
        int buyPrice=1000000001, maxProfit=-1000000001;
        
        for(int i=0; i<iniNum; i++){
            RiNum = scan.nextInt();

            maxProfit= i==0? -1000000000: Math.max(maxProfit,RiNum-buyPrice);
            buyPrice=Math.min(buyPrice,RiNum);

        }
        System.out.println(maxProfit);            
    }
}
