import java.util.Scanner;

class Main {

    public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(scan.nextLine());
        }
        
        int[] max = new int[n-1];
        int[] min = new int[n-1];
        int[] dif = new int[n-1];

        for(int i=0; i<n-1; i++){
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        }    
        
        for(int i=n-2; i>=0; i--){
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        }   
        
        for(int i=0; i<n-1; i++){
            dif[i] = max[i]-min[i];  
        }
        
        int maximum = -1000000000;
        
        for(int i=0; i<n-1; i++){
            maximum = Math.max(maximum, dif[i]);
        }
        
        System.out.println(maximum);
    }
    
} 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());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(scan.nextLine());
        }
        
        int[] max = new int[n-1];
        int[] min = new int[n-1];
        int[] dif = new int[n-1];

        for(int i=0; i<n-1; i++){
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        }    
        
        for(int i=n-2; i>=0; i--){
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        }   
        
        for(int i=0; i<n-1; i++){
            dif[i] = max[i]-min[i];  
        }
        
        int maximum = -1000000000;
        
        for(int i=0; i<n-1; i++){
            maximum = Math.max(maximum, dif[i]);
        }
        
        System.out.println(maximum);
    }
    
} Main public static void main(String[] args) {

        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(scan.nextLine());
        }
        
        int[] max = new int[n-1];
        int[] min = new int[n-1];
        int[] dif = new int[n-1];

        for(int i=0; i<n-1; i++){
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        }    
        
        for(int i=n-2; i>=0; i--){
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        }   
        
        for(int i=0; i<n-1; i++){
            dif[i] = max[i]-min[i];  
        }
        
        int maximum = -1000000000;
        
        for(int i=0; i<n-1; i++){
            maximum = Math.max(maximum, dif[i]);
        }
        
        System.out.println(maximum);
    } main {

        Scanner scan = new Scanner(System.in);
        int n = Integer.parseInt(scan.nextLine());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(scan.nextLine());
        }
        
        int[] max = new int[n-1];
        int[] min = new int[n-1];
        int[] dif = new int[n-1];

        for(int i=0; i<n-1; i++){
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        }    
        
        for(int i=n-2; i>=0; i--){
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        }   
        
        for(int i=0; i<n-1; i++){
            dif[i] = max[i]-min[i];  
        }
        
        int maximum = -1000000000;
        
        for(int i=0; i<n-1; i++){
            maximum = Math.max(maximum, dif[i]);
        }
        
        System.out.println(maximum);
    } 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 int[] a = new int[n]; a new int[n] n for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(scan.nextLine());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            a[i] = Integer.parseInt(scan.nextLine());
        } {
            a[i] = Integer.parseInt(scan.nextLine());
        } a[i] = Integer.parseInt(scan.nextLine()) a[i] a i Integer.parseInt(scan.nextLine()) Integer.parseInt Integer scan.nextLine() scan.nextLine scan int[] max = new int[n-1]; max new int[n-1] n-1 n 1 int[] min = new int[n-1]; min new int[n-1] n-1 n 1 int[] dif = new int[n-1]; dif new int[n-1] n-1 n 1 for(int i=0; i<n-1; i++){
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        } {
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        } if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);} i==0 i 0 {min[0]=a[0];} min[0]=a[0] min[0] min 0 a[0] a 0 {min[i] = Math.min(min[i-1], a[i]);} min[i] = Math.min(min[i-1], a[i]) min[i] min i Math.min(min[i-1], a[i]) Math.min Math min[i-1] min i-1 i 1 a[i] a i for(int i=n-2; i>=0; i--){
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        } int i=n-2; int i=n-2; i n-2 n 2 i>=0 i 0 i-- i-- i {
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        } {
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        } if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);} i==n-2 i n-2 n 2 {max[n-2]=a[n-1];} max[n-2]=a[n-1] max[n-2] max n-2 n 2 a[n-1] a n-1 n 1 {max[i] = Math.max(max[i+1], a[i+1]);} max[i] = Math.max(max[i+1], a[i+1]) max[i] max i Math.max(max[i+1], a[i+1]) Math.max Math max[i+1] max i+1 i 1 a[i+1] a i+1 i 1 for(int i=0; i<n-1; i++){
            dif[i] = max[i]-min[i];  
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            dif[i] = max[i]-min[i];  
        } {
            dif[i] = max[i]-min[i];  
        } dif[i] = max[i]-min[i] dif[i] dif i max[i]-min[i] max[i] max i min[i] min i int maximum = -1000000000; maximum -1000000000 1000000000 for(int i=0; i<n-1; i++){
            maximum = Math.max(maximum, dif[i]);
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            maximum = Math.max(maximum, dif[i]);
        } {
            maximum = Math.max(maximum, dif[i]);
        } maximum = Math.max(maximum, dif[i]) maximum Math.max(maximum, dif[i]) Math.max Math maximum dif[i] dif i System.out.println(maximum) System.out.println System.out System System.out maximum 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());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(scan.nextLine());
        }
        
        int[] max = new int[n-1];
        int[] min = new int[n-1];
        int[] dif = new int[n-1];

        for(int i=0; i<n-1; i++){
            if(i==0){min[0]=a[0];}
            else{min[i] = Math.min(min[i-1], a[i]);}
        }    
        
        for(int i=n-2; i>=0; i--){
            if(i==n-2){max[n-2]=a[n-1];}
            else{max[i] = Math.max(max[i+1], a[i+1]);}  
        }   
        
        for(int i=0; i<n-1; i++){
            dif[i] = max[i]-min[i];  
        }
        
        int maximum = -1000000000;
        
        for(int i=0; i<n-1; i++){
            maximum = Math.max(maximum, dif[i]);
        }
        
        System.out.println(maximum);
    }
    
}