import java.util.*;
public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	}
} import java.util.*; util.* java public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	}
} Main public static void main(String [] args){
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	} main {
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	} Scanner sc = new Scanner (System.in); sc new Scanner (System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int Rt [] = new int[n]; Rt new int[n] n for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			Rt[i] = sc.nextInt();
		} {
			Rt[i] = sc.nextInt();
		} Rt[i] = sc.nextInt() Rt[i] Rt i sc.nextInt() sc.nextInt sc int Rmax = Integer.MIN_VALUE; Rmax Integer.MIN_VALUE Integer Integer.MIN_VALUE int Rmin = Rt[0]; Rmin Rt[0] Rt 0 for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		} int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		} {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		} Rmax = Math.max(Rmax, Rt[j] - Rmin) Rmax Math.max(Rmax, Rt[j] - Rmin) Math.max Math Rmax Rt[j] - Rmin Rt[j] Rt j Rmin Rmin = Math.min(Rmin, Rt[j]) Rmin Math.min(Rmin, Rt[j]) Math.min Math Rmin Rt[j] Rt j System.out.println(Rmax) System.out.println System.out System System.out Rmax String [] args args public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	}
} public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	}
} Main
import java.util.*;
public class Main{
	public static void main(String [] args){
		Scanner sc = new Scanner (System.in);
		int n = sc.nextInt(); 
		int Rt [] = new int[n];
        for(int i = 0; i < n; i++) {
			Rt[i] = sc.nextInt();
		}
		int Rmax = Integer.MIN_VALUE;
        int Rmin = Rt[0];
		
		for(int j = 1; j < n; j++) {
			Rmax = Math.max(Rmax, Rt[j] - Rmin);
			Rmin = Math.min(Rmin, Rt[j]);
		}
		System.out.println(Rmax);
	}
}