import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	}
} Main public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	} main {
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	} Scanner std = new Scanner(System.in); std new Scanner(System.in) int n = Integer.parseInt(std.next()); n Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std int minval = Integer.parseInt(std.next()); minval Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std int maxpro = (int)-1e+9; maxpro (int)-1e+9 1e+9 int nextval = 0; nextval 0 for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		} {
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		} nextval = Integer.parseInt(std.next()) nextval Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std if(maxpro<(nextval-minval)){maxpro = nextval - minval;} maxpro<(nextval-minval) maxpro (nextval-minval) nextval minval {maxpro = nextval - minval;} maxpro = nextval - minval maxpro nextval - minval nextval minval if(nextval<minval){minval = nextval;} nextval<minval nextval minval {minval = nextval;} minval = nextval minval nextval System.out.println(maxpro) System.out.println System.out System System.out maxpro String[] args args public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	}
} public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int n = Integer.parseInt(std.next());
		int minval = Integer.parseInt(std.next());;
		int maxpro = (int)-1e+9;
		int nextval = 0;
		for (int i=1; i<n; i++){
			nextval = Integer.parseInt(std.next());
			if(maxpro<(nextval-minval)){maxpro = nextval - minval;}
			if(nextval<minval){minval = nextval;}
		}
		System.out.println(maxpro);
	}
}