import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static int getMaxNumber(int array[]){
	  int maxNumber = Integer.MIN_VALUE;
	  int minNumber = array[0];
	  for(int i = 1;i < array.length;++i){
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  }
	  return maxNumber;
  }
} import java.io.*; io.* java class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static int getMaxNumber(int array[]){
	  int maxNumber = Integer.MIN_VALUE;
	  int minNumber = array[0];
	  for(int i = 1;i < array.length;++i){
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  }
	  return maxNumber;
  }
} Main public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    }
  } main {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    }
  } try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    } catch(Exception e){
      System.out.println(e);
    } Exception e {
      System.out.println(e);
    } System.out.println(e) System.out.println System.out System System.out e {
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    } 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[] array = new int[n]; array new int[n] n int putnum = 0; putnum 0 while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      } true {
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      } String str = br.readLine(); str br.readLine() br.readLine br array[putnum] = Integer.parseInt(str) array[putnum] array putnum Integer.parseInt(str) Integer.parseInt Integer str if(++putnum == n)break; ++putnum == n ++putnum putnum n break; System.out.println(String.valueOf(getMaxNumber(array))) System.out.println System.out System System.out String.valueOf(getMaxNumber(array)) String.valueOf String getMaxNumber(array) getMaxNumber array String[] args args public static int getMaxNumber(int array[]){
	  int maxNumber = Integer.MIN_VALUE;
	  int minNumber = array[0];
	  for(int i = 1;i < array.length;++i){
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  }
	  return maxNumber;
  } getMaxNumber {
	  int maxNumber = Integer.MIN_VALUE;
	  int minNumber = array[0];
	  for(int i = 1;i < array.length;++i){
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  }
	  return maxNumber;
  } int maxNumber = Integer.MIN_VALUE; maxNumber Integer.MIN_VALUE Integer Integer.MIN_VALUE int minNumber = array[0]; minNumber array[0] array 0 for(int i = 1;i < array.length;++i){
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  } int i = 1; int i = 1; i 1 i < array.length i array.length array array.length ++i ++i i {
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  } {
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  } final int divide = array[i] - minNumber; divide array[i] - minNumber array[i] array i minNumber if(divide > maxNumber){
			  maxNumber = divide;
		  } divide > maxNumber divide maxNumber {
			  maxNumber = divide;
		  } maxNumber = divide maxNumber divide if(minNumber > array[i]){
			  minNumber = array[i];
		  } minNumber > array[i] minNumber array[i] array i {
			  minNumber = array[i];
		  } minNumber = array[i] minNumber array[i] array i return maxNumber; maxNumber int array[] array
import java.io.*;

class Main
{
 
  public static void main(String[] args)
  {
    try{
    	// ??\???????????????
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      // ????????°???????????????
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      int putnum = 0;
      while(true){
    	  String str = br.readLine();
    	  array[putnum] = Integer.parseInt(str);
    	  if(++putnum == n)break;
      }
      
      System.out.println(String.valueOf(getMaxNumber(array)));
 
    }catch(Exception e){
      System.out.println(e);
    }
  }
 
  public static int getMaxNumber(int array[]){
	  int maxNumber = Integer.MIN_VALUE;
	  int minNumber = array[0];
	  for(int i = 1;i < array.length;++i){
		  final int divide = array[i] - minNumber;
		  
		  if(divide > maxNumber){
			  maxNumber = divide;
		  }
		  
		  if(minNumber > array[i]){
			  minNumber = array[i];
		  }
	  }
	  return maxNumber;
  }
}