import java.util.Scanner;

public class Main{
 
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    }
}
 import java.util.Scanner; Scanner java.util public class Main{
 
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    }
} Main public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    } main {
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int i i j j n n max=0 max 0 min=0 min 0 dist=0; dist 0 n=scan.nextInt() n scan.nextInt() scan.nextInt scan int r[]=new int [n]; r new int [n] n for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        } i=0; i=0 i 0 i<n i n i++ i++ i {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        } {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        } r[i]=scan.nextInt() r[i] r i scan.nextInt() scan.nextInt scan if(r[max]<r[i]) {
                max=i;
            } r[max]<r[i] r[max] r max r[i] r i {
                max=i;
            } max=i max i if(r[min]>r[i]) {
                min=i;
            } r[min]>r[i] r[min] r min r[i] r i {
                min=i;
            } min=i min i if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        } min<max min max {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        } System.out.println(r[max]-r[min]) System.out.println System.out System System.out r[max]-r[min] r[max] r max r[min] r min scan.close() scan.close scan return; min=r[0] min r[0] r 0 for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        } i=1; i=1 i 1 i<n i n i++ i++ i {
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        } {
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        } if(i==1){
        		dist=r[i]-min;
        	} i==1 i 1 {
        		dist=r[i]-min;
        	} dist=r[i]-min dist r[i]-min r[i] r i min if(dist<r[i]-min){
        		dist=r[i]-min;
        	} dist<r[i]-min dist r[i]-min r[i] r i min {
        		dist=r[i]-min;
        	} dist=r[i]-min dist r[i]-min r[i] r i min if(min>r[i]){
        		min=r[i];
        	} min>r[i] min r[i] r i {
        		min=r[i];
        	} min=r[i] min r[i] r i System.out.println(dist) System.out.println System.out System System.out dist scan.close() scan.close scan String[] args args public class Main{
 
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    }
} public class Main{
 
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    }
} Main
import java.util.Scanner;

public class Main{
 
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int i,j,n,max=0,min=0,dist=0;
        n=scan.nextInt();
        int r[]=new int [n];
        for(i=0;i<n;i++) {
            r[i]=scan.nextInt();
            if(r[max]<r[i]) {
                max=i;
            }
            if(r[min]>r[i]) {
                min=i;
            }
        }
        if(min<max) {
            System.out.println(r[max]-r[min]);
            scan.close();
            return;
        }
        
        min=r[0];
        for(i=1;i<n;i++){
        	if(i==1){
        		dist=r[i]-min;
        	}
        	if(dist<r[i]-min){
        		dist=r[i]-min;
        	}
        	if(min>r[i]){
        		min=r[i];
        	}
        }
        System.out.println(dist);
        scan.close();
    }
}

