import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	}
} import java.util.Scanner; Scanner java.util public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	}
} Main public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	} main {
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	} Scanner s=new Scanner(System.in); s new Scanner(System.in) int n=s.nextInt(); n s.nextInt() s.nextInt s int a[]=new int[n]; a new int[n] n for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			a[i]=s.nextInt();
		} {
			a[i]=s.nextInt();
		} a[i]=s.nextInt() a[i] a i s.nextInt() s.nextInt s int max=a[1]-a[0]; max a[1]-a[0] a[1] a 1 a[0] a 0 int min=a[0]; min a[0] a 0 for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		} int j=2; int j=2; j 2 j<n j n j++ j++ j {
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		} {
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		} min=Math.min(min,a[j-1]) min Math.min(min,a[j-1]) Math.min Math min a[j-1] a j-1 j 1 int sub; sub sub=a[j]-min sub a[j]-min a[j] a j min if(sub>max) max=sub; sub>max sub max max=sub max sub 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 s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	}
} public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	}
} Main
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=s.nextInt();
		}
		int max=a[1]-a[0];
		int min=a[0];
		for(int j=2;j<n;j++){
			min=Math.min(min,a[j-1]);
			int sub;
			sub=a[j]-min;
			if(sub>max) max=sub;
		}
		System.out.println(max);
	}
}
