import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R[] = new int[N];
		int i, j;
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		}
		for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		}
		System.out.println(max);
	}
} import java.util.Scanner; Scanner java.util class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R[] = new int[N];
		int i, j;
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		}
		for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		}
		System.out.println(max);
	}
} Main public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R[] = new int[N];
		int i, j;
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		}
		for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		}
		System.out.println(max);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R[] = new int[N];
		int i, j;
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		}
		for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		}
		System.out.println(max);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int R[] = new int[N]; R new int[N] N int i i j; j int min=Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE int max=Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		} i=0; i=0 i 0 i<N i N i++ i++ i {
			R[i] = sc.nextInt();
		} {
			R[i] = sc.nextInt();
		} R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		} i=0; i=0 i 0 i<N-1 i N-1 N 1 i++ i++ i {
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		} {
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		} if(min<=R[i]) continue; min<=R[i] min R[i] R i continue; min=R[i] min R[i] R i for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			} j=i+1; j=i+1 j i+1 i 1 j<N j N j++ j++ j {
				if(max<R[j]-R[i]) max=R[j]-R[i];
			} {
				if(max<R[j]-R[i]) max=R[j]-R[i];
			} if(max<R[j]-R[i]) max=R[j]-R[i]; max<R[j]-R[i] max R[j]-R[i] R[j] R j R[i] R i max=R[j]-R[i] max R[j]-R[i] R[j] R j R[i] R i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int R[] = new int[N];
		int i, j;
		int min=Integer.MAX_VALUE;
		int max=Integer.MIN_VALUE;
		for(i=0; i<N; i++){
			R[i] = sc.nextInt();
		}
		for(i=0; i<N-1; i++){
			if(min<=R[i]) continue;
			min=R[i];
			for(j=i+1; j<N; j++){
				if(max<R[j]-R[i]) max=R[j]-R[i];
			}
		}
		System.out.println(max);
	}
}