import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    }
} Main public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    } main {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    } try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        } {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String line; line int n=0 n 0 j=0; j 0 int[] store=null; store null boolean first=true first true min_flag=true; min_flag true while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            } (line = br.readLine()) != null (line = br.readLine()) line br.readLine() br.readLine br null {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            } if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	} first {
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	} n=Integer.parseInt(line) n Integer.parseInt(line) Integer.parseInt Integer line store=new int[n] store new int[n] n first=false first false {
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	} store[j]=Integer.parseInt(line) store[j] store j Integer.parseInt(line) Integer.parseInt Integer line j++ j if(j==n){
            			break;
            		} j==n j n {
            			break;
            		} break; int s=0; s 0 int result=store[1]-store[0]; result store[1]-store[0] store[1] store 1 store[0] store 0 int min=store[0] min store[0] store 0 max=min; max min for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            } int i=1; int i=1; i 1 i<n i n i++ i++ i {
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            } {
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            } if(min_flag){
            		s=store[i];
           		} min_flag {
            		s=store[i];
           		} s=store[i] s store[i] store i min_flag=true min_flag true if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	} s<=min&&i!=n-1 s<=min s min i!=n-1 i n-1 n 1 {
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            } min=s min s if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		} i==n-2 i n-2 n 2 {
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		} max=store[i+1] max store[i+1] store i+1 i 1 if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			} max-min>result max-min max min result {
	            			System.out.println(max-min);
	            		} System.out.println(max-min) System.out.println System.out System System.out max-min max min {
	           				System.out.println(result);
	           			} System.out.println(result) System.out.println System.out System System.out result return; {
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		} s=store[i+1] s store[i+1] store i+1 i 1 max=s max s if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			} result<max-min result max-min max min {
	           				result=max-min;
	           			} result=max-min result max-min max min {
	           				min_flag=false;
	           			} min_flag=false min_flag false if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	} s>=max s max {
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	} max=s max s if(max-min>result){
	           			result=max-min;
	           		} max-min>result max-min max min result {
	           			result=max-min;
	           		} result=max-min result max-min max min System.out.println(result) System.out.println System.out System System.out result String[] args args public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    }
} public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            int n=0,j=0;
            int[] store=null;
            boolean first=true,min_flag=true;
            while ((line = br.readLine()) != null) {
            	if(first){
            		n=Integer.parseInt(line);
            		store=new int[n];
            		first=false;
            	}else{
            		store[j]=Integer.parseInt(line);
            		j++;
            		if(j==n){
            			break;
            		}
            	}           	
            }
            int s=0;
            int result=store[1]-store[0];
            int min=store[0],max=min;
            for(int i=1;i<n;i++){
            	if(min_flag){
            		s=store[i];
           		}
            	//System.out.println(i);
            	min_flag=true;
           		if(s<=min&&i!=n-1){
           			//System.out.println(s);
            		min=s;
	            	if(i==n-2){
	           			max=store[i+1];
	            		if(max-min>result){
	            			System.out.println(max-min);
	            		}else{
	           				System.out.println(result);
	           			}
	           			return;
	           		}else{
	           			s=store[i+1];
	           			max=s;
	           			if(result<max-min){
	           				result=max-min;
	           			}else{
	           				min_flag=false;
	           			}
	           		}
	            }else if(s>=max){
	           		max=s;
	           		if(max-min>result){
	           			result=max-min;
	           		}
	          	}
            		
            }
            	
            System.out.println(result);
        }
    }
}