import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	}
} import java.io.*; io.* java import java.util.ArrayDeque; ArrayDeque java.util import java.util.ArrayList; ArrayList java.util import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util import java.util.Scanner; Scanner java.util public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	}
} Main static String a; a public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] list = new int[n]; list new int[n] n int maxAns = Integer.MIN_VALUE; maxAns Integer.MIN_VALUE Integer Integer.MIN_VALUE list[0] = stdIn.nextInt() list[0] list 0 stdIn.nextInt() stdIn.nextInt stdIn int min = list[0]; min list[0] list 0 int max = -2000000000; max -2000000000 2000000000 for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		} {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		} list[i] = stdIn.nextInt() list[i] list i stdIn.nextInt() stdIn.nextInt stdIn max = list[i] max list[i] list i if(maxAns < max - min) {
				maxAns = max - min;
			} maxAns < max - min maxAns max - min max min {
				maxAns = max - min;
			} maxAns = max - min maxAns max - min max min if(min > list[i]) {
				min = list[i];
			} min > list[i] min list[i] list i {
				min = list[i];
			} min = list[i] min list[i] list i System.out.println(maxAns) System.out.println System.out System System.out maxAns String[] args args public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	}
} public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	}
} Main
import java.io.*;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
public class Main {
	static String a;
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] list = new int[n];
		int maxAns = Integer.MIN_VALUE;
		
		list[0] = stdIn.nextInt();
		int min = list[0];
		int max = -2000000000;
		for(int i = 1; i < n; i++) {
			list[i] = stdIn.nextInt();
			max = list[i];
			if(maxAns < max - min) {
				maxAns = max - min;
			}
			if(min > list[i]) {
				min = list[i];
			}
			
			
		}
		
		
		System.out.println(maxAns);
	}
}