import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] r = new int[n];
		int ans;
		
		for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		}
		
		int maxv = r[1]-r[0];
		int minv = r[0];
		
		for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		}
		System.out.println(maxv);
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] r = new int[n];
		int ans;
		
		for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		}
		
		int maxv = r[1]-r[0];
		int minv = r[0];
		
		for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		}
		System.out.println(maxv);
	}
} Main public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] r = new int[n];
		int ans;
		
		for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		}
		
		int maxv = r[1]-r[0];
		int minv = r[0];
		
		for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		}
		System.out.println(maxv);
	} main {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] r = new int[n];
		int ans;
		
		for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		}
		
		int maxv = r[1]-r[0];
		int minv = r[0];
		
		for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		}
		System.out.println(maxv);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] r = new int[n]; r new int[n] n int ans; ans for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			r[i] = scan.nextInt();
		} {
			r[i] = scan.nextInt();
		} r[i] = scan.nextInt() r[i] r i scan.nextInt() scan.nextInt scan int maxv = r[1]-r[0]; maxv r[1]-r[0] r[1] r 1 r[0] r 0 int minv = r[0]; minv r[0] r 0 for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		} {
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		} maxv = Math.max(maxv, r[i]-minv) maxv Math.max(maxv, r[i]-minv) Math.max Math maxv r[i]-minv r[i] r i minv minv = Math.min(minv, r[i]) minv Math.min(minv, r[i]) Math.min Math minv r[i] r i System.out.println(maxv) System.out.println System.out System System.out maxv String args[] args
import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] r = new int[n];
		int ans;
		
		for(int i = 0; i < n; i++){
			r[i] = scan.nextInt();
		}
		
		int maxv = r[1]-r[0];
		int minv = r[0];
		
		for(int i = 1; i < n; i++){
			maxv = Math.max(maxv, r[i]-minv);
			minv = Math.min(minv, r[i]);
		}
		System.out.println(maxv);
	}
}