


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );

   int[] R = new int[n];

   for(int i = 0; i < n; i++){

	   R[i] = Integer.parseInt( br.readLine() );

   }

   int maxv = R[1] - R[0];
   int minv = R[0];

   for(int j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   }


   System.out.println(maxv);


 }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );

   int[] R = new int[n];

   for(int i = 0; i < n; i++){

	   R[i] = Integer.parseInt( br.readLine() );

   }

   int maxv = R[1] - R[0];
   int minv = R[0];

   for(int j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   }


   System.out.println(maxv);


 }
} Main public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );

   int[] R = new int[n];

   for(int i = 0; i < n; i++){

	   R[i] = Integer.parseInt( br.readLine() );

   }

   int maxv = R[1] - R[0];
   int minv = R[0];

   for(int j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   }


   System.out.println(maxv);


 } main {
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );

   int[] R = new int[n];

   for(int i = 0; i < n; i++){

	   R[i] = Integer.parseInt( br.readLine() );

   }

   int maxv = R[1] - R[0];
   int minv = R[0];

   for(int j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   }


   System.out.println(maxv);


 } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt( br.readLine() ); n Integer.parseInt( br.readLine() ) Integer.parseInt Integer br.readLine() br.readLine br int[] R = new int[n]; R new int[n] n for(int i = 0; i < n; i++){

	   R[i] = Integer.parseInt( br.readLine() );

   } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {

	   R[i] = Integer.parseInt( br.readLine() );

   } {

	   R[i] = Integer.parseInt( br.readLine() );

   } R[i] = Integer.parseInt( br.readLine() ) R[i] R i Integer.parseInt( br.readLine() ) Integer.parseInt Integer br.readLine() br.readLine br 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 j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   } int j = 1 ; int j = 1 ; j 1 j < n j n j++ j++ j {

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   } {

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   } if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   } R[j]-minv > maxv R[j]-minv R[j] R j minv maxv {
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   } maxv = R[j]-minv maxv R[j]-minv R[j] R j minv if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   } minv > R[j] minv R[j] R j {
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   } minv = R[j] minv R[j] R j System.out.println(maxv) System.out.println System.out System System.out maxv String args[] args



import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );

   int[] R = new int[n];

   for(int i = 0; i < n; i++){

	   R[i] = Integer.parseInt( br.readLine() );

   }

   int maxv = R[1] - R[0];
   int minv = R[0];

   for(int j = 1 ; j < n ;j++){

	   if(R[j]-minv > maxv ){
		   maxv = R[j]-minv;
		   //System.out.println("maxv= "+maxv);
	   }

	   if(minv > R[j] ){
		   minv = R[j];
		  // System.out.println("minv= "+minv);
	   }

   }


   System.out.println(maxv);


 }
}