import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		int max = num[1] - num[0];
		
		/*for(int j = 1; j < input - 1; j++){
			for(int i = 0; i< j - 1; i++){
				max = Math.max(max, num[j] - num[i]);
			}
		}*/
		
		int min = num[0];
		for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		}
		
		System.out.println(max);
	}
} import java.util.Scanner; Scanner java.util class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		int max = num[1] - num[0];
		
		/*for(int j = 1; j < input - 1; j++){
			for(int i = 0; i< j - 1; i++){
				max = Math.max(max, num[j] - num[i]);
			}
		}*/
		
		int min = num[0];
		for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		}
		
		System.out.println(max);
	}
} Main public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		int max = num[1] - num[0];
		
		/*for(int j = 1; j < input - 1; j++){
			for(int i = 0; i< j - 1; i++){
				max = Math.max(max, num[j] - num[i]);
			}
		}*/
		
		int min = num[0];
		for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		}
		
		System.out.println(max);
	} main {
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		int max = num[1] - num[0];
		
		/*for(int j = 1; j < input - 1; j++){
			for(int i = 0; i< j - 1; i++){
				max = Math.max(max, num[j] - num[i]);
			}
		}*/
		
		int min = num[0];
		for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		}
		
		System.out.println(max);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int input = scan.nextInt(); input scan.nextInt() scan.nextInt scan int[] num = new int[input]; num new int[input] input for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		} int c = 0; int c = 0; c 0 c < input c input c++ c++ c {
			num[c] = scan.nextInt();
		} {
			num[c] = scan.nextInt();
		} num[c] = scan.nextInt() num[c] num c scan.nextInt() scan.nextInt scan int max = num[1] - num[0]; max num[1] - num[0] num[1] num 1 num[0] num 0 int min = num[0]; min num[0] num 0 for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		} int j = 1; int j = 1; j 1 j <= input - 1 j input - 1 input 1 j++ j++ j {
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		} {
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		} max = Math.max(max, num[j] - min) max Math.max(max, num[j] - min) Math.max Math max num[j] - min num[j] num j min min = Math.min(min, num[j]) min Math.min(min, num[j]) Math.min Math min num[j] num j System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.Scanner;
class Main {
   public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int input = scan.nextInt();
		int[] num = new int[input];
		
		for(int c = 0; c < input; c++){
			num[c] = scan.nextInt();
		}
		
		int max = num[1] - num[0];
		
		/*for(int j = 1; j < input - 1; j++){
			for(int i = 0; i< j - 1; i++){
				max = Math.max(max, num[j] - num[i]);
			}
		}*/
		
		int min = num[0];
		for(int j = 1; j <= input - 1; j++){
			max = Math.max(max, num[j] - min);
			min = Math.min(min, num[j]);
		}
		
		System.out.println(max);
	}
}