import java.util.*;


class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int maxProfit = b - a;
        
        int min = Math.min(a,b);  // the minimum number in the dataset 

        while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        }


        System.out.println(maxProfit);
    }
} import java.util.*; util.* java class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int maxProfit = b - a;
        
        int min = Math.min(a,b);  // the minimum number in the dataset 

        while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        }


        System.out.println(maxProfit);
    }
} Main public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int maxProfit = b - a;
        
        int min = Math.min(a,b);  // the minimum number in the dataset 

        while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        }


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

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int maxProfit = b - a;
        
        int min = Math.min(a,b);  // the minimum number in the dataset 

        while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        }


        System.out.println(maxProfit);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int a = sc.nextInt(); a sc.nextInt() sc.nextInt sc int b = sc.nextInt(); b sc.nextInt() sc.nextInt sc int maxProfit = b - a; maxProfit b - a b a int min = Math.min(a,b); min Math.min(a,b) Math.min Math a b while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        } sc.hasNextInt() sc.hasNextInt sc {
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        } int next = sc.nextInt(); next sc.nextInt() sc.nextInt sc maxProfit = Math.max(maxProfit, next - min) maxProfit Math.max(maxProfit, next - min) Math.max Math maxProfit next - min next min min = Math.min(min, next) min Math.min(min, next) Math.min Math min next System.out.println(maxProfit) System.out.println System.out System System.out maxProfit String[] args args
import java.util.*;


class Main {

    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();

        int a = sc.nextInt();
        int b = sc.nextInt();
        
        int maxProfit = b - a;
        
        int min = Math.min(a,b);  // the minimum number in the dataset 

        while(sc.hasNextInt()){
            int next = sc.nextInt();
            
            maxProfit = Math.max(maxProfit, next - min);
            
            min = Math.min(min, next);
        }


        System.out.println(maxProfit);
    }
}
