import java.util.*;
public class Main{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   }//main
} import java.util.*; util.* java public class Main{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   }//main
} Main public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   }//main main {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
      arr[i] = Integer.parseInt(sc.nextLine());
   } {
      arr[i] = Integer.parseInt(sc.nextLine());
   } arr[i] = Integer.parseInt(sc.nextLine()) arr[i] arr i Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int min = arr[0]; min arr[0] arr 0 int maxP = arr[1] - arr[0]; maxP arr[1] - arr[0] arr[1] arr 1 arr[0] arr 0 for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   } int i = 1; int i = 1; i 1 i < n i n i ++ i ++ i {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   } {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   } int dif = arr[i] - min; dif arr[i] - min arr[i] arr i min if(dif > maxP) {
         maxP = dif;  
      } dif > maxP dif maxP {
         maxP = dif;  
      } maxP = dif maxP dif if(arr[i] < min) {
         min = arr[i];
      } arr[i] < min arr[i] arr i min {
         min = arr[i];
      } min = arr[i] min arr[i] arr i System.out.println(maxP) System.out.println System.out System System.out maxP String[] args args public class Main{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   }//main
} public class Main{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   }//main
} Main
import java.util.*;
public class Main{
   public static void main(String[] args) {
   Scanner sc = new Scanner(System.in);
   
   int n = Integer.parseInt(sc.nextLine());
   int[] arr = new int[n];
   
   for(int i = 0; i < n; i ++) {
      arr[i] = Integer.parseInt(sc.nextLine());
   }
   
   int min = arr[0];
   int maxP = arr[1] - arr[0];
   
   for(int i = 1; i < n; i ++) {
      int dif = arr[i] - min;
      if(dif > maxP) {
         maxP = dif;  
      }
      if(arr[i] < min) {
         min = arr[i];
      }
   }
   
   System.out.println(maxP);
    
   }//main
}
