

import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		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 R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		System.out.println(max);
	}
} Main public static void main(String[] args){
		
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		System.out.println(max);
	} main {
		
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		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 R[]=new int[n]; R new int[n] n for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			R[i]=s.nextInt();
		} {
			R[i]=s.nextInt();
		} R[i]=s.nextInt() R[i] R i s.nextInt() s.nextInt s int ri=R[0]; ri R[0] R 0 int max=R[1]-ri; max R[1]-ri R[1] R 1 ri for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		} int i=2; int i=2; i 2 i<R.length i R.length R R.length i++ i++ i {
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		} {
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		} if(ri>R[i-1])ri=R[i-1]; ri>R[i-1] ri R[i-1] R i-1 i 1 ri=R[i-1] ri R[i-1] R i-1 i 1 if(max<R[i]-ri)max=R[i]-ri; max<R[i]-ri max R[i]-ri R[i] R i ri max=R[i]-ri max R[i]-ri R[i] R i ri 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 R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		System.out.println(max);
	}
} public class Main {
	public static void main(String[] args){
		
		Scanner s=new Scanner(System.in);
		int n=s.nextInt();
		int R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		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 R[]=new int[n];
		for(int i=0;i<n;i++){
			R[i]=s.nextInt();
		}
		//ri ?????????
		int ri=R[0];
		//rj ???????????????
		int max=R[1]-ri;
		for(int i=2;i<R.length;i++){
			if(ri>R[i-1])ri=R[i-1];
			if(max<R[i]-ri)max=R[i]-ri;
		}
		System.out.println(max);
	}
}