import java.util.Scanner;
public class Main {
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	}
} Main public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	} main {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int [] arr = new int [n]; arr new int [n] n int maxVal = Integer.MIN_VALUE; maxVal Integer.MIN_VALUE Integer Integer.MIN_VALUE for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = in.nextInt();
		} {
			arr[i] = in.nextInt();
		} arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in int biggestNum = arr[n - 1]; biggestNum arr[n - 1] arr n - 1 n 1 for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	} int j = n - 1; int j = n - 1; j n - 1 n 1 j > 0 j 0 j-- j-- j {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	} {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	} biggestNum = Math.max(arr[j], biggestNum) biggestNum Math.max(arr[j], biggestNum) Math.max Math arr[j] arr j biggestNum if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 } biggestNum - arr[j - 1] > maxVal biggestNum - arr[j - 1] biggestNum arr[j - 1] arr j - 1 j 1 maxVal {
				 maxVal = biggestNum - arr[j - 1];
			 } maxVal = biggestNum - arr[j - 1] maxVal biggestNum - arr[j - 1] biggestNum arr[j - 1] arr j - 1 j 1 System.out.println(maxVal) System.out.println System.out System System.out maxVal String [] args args public class Main {
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	}
} public class Main {
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	}
} Main
import java.util.Scanner;
public class Main {
	
	public static void main(String [] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		
		
		int [] arr = new int [n];
		
		
		int maxVal = Integer.MIN_VALUE;
		
		
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		int biggestNum = arr[n - 1];
		
		for(int j = n - 1; j > 0; j--) {
			
			 biggestNum = Math.max(arr[j], biggestNum);
			
			 
			 if(biggestNum - arr[j - 1] > maxVal) {
				 maxVal = biggestNum - arr[j - 1];
			 }
			 	
	}
		
		System.out.println(maxVal);
		
		

	}
}

