import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		int max = 0;
		int min = 0;
		for(int i=0;i<times;i++){
			num[i] = scan.nextInt();
			
		}
		max = num[1] - num[0];
		min = num[0];
		for(int i=1;i<times;i++){
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		}
		System.out.println(max);
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		int max = 0;
		int min = 0;
		for(int i=0;i<times;i++){
			num[i] = scan.nextInt();
			
		}
		max = num[1] - num[0];
		min = num[0];
		for(int i=1;i<times;i++){
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		}
		System.out.println(max);
	}
} Main public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		int max = 0;
		int min = 0;
		for(int i=0;i<times;i++){
			num[i] = scan.nextInt();
			
		}
		max = num[1] - num[0];
		min = num[0];
		for(int i=1;i<times;i++){
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		}
		System.out.println(max);
	} main {
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		int max = 0;
		int min = 0;
		for(int i=0;i<times;i++){
			num[i] = scan.nextInt();
			
		}
		max = num[1] - num[0];
		min = num[0];
		for(int i=1;i<times;i++){
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		}
		System.out.println(max);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int times = scan.nextInt(); times scan.nextInt() scan.nextInt scan int num[] =new int[times]; num new int[times] times int max = 0; max 0 int min = 0; min 0 for(int i=0;i<times;i++){
			num[i] = scan.nextInt();
			
		} int i=0; int i=0; i 0 i<times i times i++ i++ i {
			num[i] = scan.nextInt();
			
		} {
			num[i] = scan.nextInt();
			
		} num[i] = scan.nextInt() num[i] num i scan.nextInt() scan.nextInt scan max = num[1] - num[0] max num[1] - num[0] num[1] num 1 num[0] num 0 min = num[0] min num[0] num 0 for(int i=1;i<times;i++){
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		} int i=1; int i=1; i 1 i<times i times i++ i++ i {
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		} {
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		} if(max < num[i]-min){
				max = num[i]-min;
			} max < num[i]-min max num[i]-min num[i] num i min {
				max = num[i]-min;
			} max = num[i]-min max num[i]-min num[i] num i min if(min > num[i]){
				min = num[i];
			} min > num[i] min num[i] num i {
				min = num[i];
			} min = num[i] min num[i] num i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.IOException;
import java.util.Scanner;
class Main{
	public static void main(String[] args)throws NumberFormatException, IOException{
//		System.out.println(" ");
		Scanner scan = new Scanner(System.in);
		int times = scan.nextInt();
		int num[] =new int[times];
		int max = 0;
		int min = 0;
		for(int i=0;i<times;i++){
			num[i] = scan.nextInt();
			
		}
		max = num[1] - num[0];
		min = num[0];
		for(int i=1;i<times;i++){
			if(max < num[i]-min){
				max = num[i]-min;
			}
			if(min > num[i]){
				min = num[i];
			}
		}
		System.out.println(max);
	}
}