// ALDS1_1_D Maximum Profit
import java.io.*;

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

      try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static int max(int[] R, int n) {
      int maxv = Integer.MIN_VALUE;
      int minv = R[0];
      for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      }
      return maxv;
   }
} import java.io.*; io.* java class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static int max(int[] R, int n) {
      int maxv = Integer.MIN_VALUE;
      int minv = R[0];
      for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      }
      return maxv;
   }
} Main public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   } main {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      } catch (Exception e) {
         e.printStackTrace();
      } Exception e {
         e.printStackTrace();
      } e.printStackTrace() e.printStackTrace e {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      } 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 System.out.println(max(R, n)) System.out.println System.out System System.out max(R, n) max R n String[] args args static int max(int[] R, int n) {
      int maxv = Integer.MIN_VALUE;
      int minv = R[0];
      for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      }
      return maxv;
   } max {
      int maxv = Integer.MIN_VALUE;
      int minv = R[0];
      for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      }
      return maxv;
   } int maxv = Integer.MIN_VALUE; maxv Integer.MIN_VALUE Integer Integer.MIN_VALUE int minv = R[0]; minv R[0] R 0 for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      } int j = 1; int j = 1; j 1 j < n j n j++ j++ j {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      } {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      } maxv = maxv > R[j] - minv ? maxv : R[j] - minv maxv maxv > R[j] - minv ? maxv : R[j] - minv maxv > R[j] - minv maxv R[j] - minv R[j] R j minv maxv R[j] - minv R[j] R j minv minv = minv < R[j] ? minv : R[j] minv minv < R[j] ? minv : R[j] minv < R[j] minv R[j] R j minv R[j] R j return maxv; maxv int[] R R int n n
// ALDS1_1_D Maximum Profit
import java.io.*;

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

      try {
         int n = Integer.parseInt(br.readLine());
         int[] R = new int[n];
         for (int i = 0; i < n; i++) {
            R[i] = Integer.parseInt(br.readLine());
         }
         System.out.println(max(R, n));
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static int max(int[] R, int n) {
      int maxv = Integer.MIN_VALUE;
      int minv = R[0];
      for (int j = 1; j < n; j++) {
         maxv = maxv > R[j] - minv ? maxv : R[j] - minv;
         minv = minv < R[j] ? minv : R[j];
      }
      return maxv;
   }
}