import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	}
	
	public static int calcMaxDifference(int[] r, int n) {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	}
	
	public static int calcMaxDifference(int[] r, int n) {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	} main {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int[] r = new int[200000]; r new int[200000] 200000 int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i r[i] = stdIn.nextInt(); r[i] = stdIn.nextInt() r[i] r i stdIn.nextInt() stdIn.nextInt stdIn int ans = calcMaxDifference(r, n); ans calcMaxDifference(r, n) calcMaxDifference r n System.out.println(ans) System.out.println System.out System System.out ans String[] args args public static int calcMaxDifference(int[] r, int n) {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	} calcMaxDifference {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	} int max = r[1] - r[0]; max r[1] - r[0] r[1] r 1 r[0] r 0 int rmin = r[0]; rmin r[0] r 0 for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		} {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		} max = (max > r[i] - rmin ? max : r[i] - rmin) max (max > r[i] - rmin ? max : r[i] - rmin) max > r[i] - rmin max r[i] - rmin r[i] r i rmin max r[i] - rmin r[i] r i rmin rmin = (rmin < r[i] ? rmin : r[i]) rmin (rmin < r[i] ? rmin : r[i]) rmin < r[i] rmin r[i] r i rmin r[i] r i return max; max int[] r r int n n public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	}
	
	public static int calcMaxDifference(int[] r, int n) {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	}
} public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	}
	
	public static int calcMaxDifference(int[] r, int n) {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int[] r = new int[200000];
		
		int n = stdIn.nextInt();
		
		for (int i = 0; i < n; i++)
			r[i] = stdIn.nextInt();
		
		int ans = calcMaxDifference(r, n);
		System.out.println(ans);
	}
	
	public static int calcMaxDifference(int[] r, int n) {
		int max = r[1] - r[0];
		int rmin = r[0];
		
		for (int i = 1; i < n; i++) {
			max = (max > r[i] - rmin ? max : r[i] - rmin);
			rmin = (rmin < r[i] ? rmin : r[i]);
		}
		return max;
	}
}