import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	} main {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[] R = new int[n]; R new int[n] n for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			R[i] = Integer.parseInt(sc.next());
		} {
			R[i] = Integer.parseInt(sc.next());
		} R[i] = Integer.parseInt(sc.next()) R[i] R i Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc 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++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		} {
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		} if(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 max R[i]-Rmin R[i] R i Rmin if(Rmin>R[i]) Rmin=R[i]; Rmin>R[i] Rmin R[i] R i Rmin=R[i] Rmin R[i] R i System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] R = new int[n];
		
		for(int i=0;i<n;i++){
			R[i] = Integer.parseInt(sc.next());
		}
		
		int max=R[1]-R[0];
		int Rmin=R[0];
		for(int i=1;i<n;i++){
			if(max<R[i]-Rmin) max=R[i]-Rmin;
			if(Rmin>R[i]) Rmin=R[i];
		}
		System.out.println(max);

	}

}