import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int min = numbers[0];
		long max = -999999999999l;
		for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		}
		System.out.println(max);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int min = numbers[0];
		long max = -999999999999l;
		for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		}
		System.out.println(max);
	}
} Main public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int min = numbers[0];
		long max = -999999999999l;
		for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		}
		System.out.println(max);
	} main {
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int min = numbers[0];
		long max = -999999999999l;
		for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		}
		System.out.println(max);
	} BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] numbers = new int[n]; numbers new int[n] n for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
		    numbers[i] = scanner.nextInt();
		} {
		    numbers[i] = scanner.nextInt();
		} numbers[i] = scanner.nextInt() numbers[i] numbers i scanner.nextInt() scanner.nextInt scanner int min = numbers[0]; min numbers[0] numbers 0 long max = -999999999999l; max -999999999999l 999999999999l for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		} {
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		} if(numbers[i] - min > max){
				max = numbers[i] - min;
			} numbers[i] - min > max numbers[i] - min numbers[i] numbers i min max {
				max = numbers[i] - min;
			} max = numbers[i] - min max numbers[i] - min numbers[i] numbers i min if(numbers[i] < min){
				min = numbers[i];
			} numbers[i] < min numbers[i] numbers i min {
				min = numbers[i];
			} min = numbers[i] min numbers[i] numbers i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader br = 
			new BufferedReader(new InputStreamReader(System.in));
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] numbers = new int[n];
		for(int i = 0; i < n; i++){
		    numbers[i] = scanner.nextInt();
		}
		int min = numbers[0];
		long max = -999999999999l;
		for(int i = 1; i < n; i++){
			if(numbers[i] - min > max){
				max = numbers[i] - min;
			}
			if(numbers[i] < min){
				min = numbers[i];
			}
		}
		System.out.println(max);
	}
}