/* ALDS1_1_D */
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 max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }catch(Exception e){
      System.out.println(e);
    }
  }
} 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 max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }catch(Exception e){
      System.out.println(e);
    }
  }
} Main public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      int max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }catch(Exception e){
      System.out.println(e);
    }
  } main {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      int max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }catch(Exception e){
      System.out.println(e);
    }
  } try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      int n = Integer.parseInt(br.readLine());
      int max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }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 max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    } 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 max = 0 max 0 min = 0; min 0 for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      } {
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      } int v = Integer.parseInt(br.readLine()); v Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br if(i == 0){
          min = v;
          continue;
        } i == 0 i 0 {
          min = v;
          continue;
        } min = v min v continue; if(max < v - min || i == 1){
          max = v - min;
        } max < v - min || i == 1 max < v - min max v - min v min i == 1 i 1 {
          max = v - min;
        } max = v - min max v - min v min if(min > v) min = v; min > v min v min = v min v System.out.println(max) System.out.println System.out System System.out max String[] args args
/* ALDS1_1_D */
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 max = 0, min = 0;

      for(int i = 0; i < n; i++){
        int v = Integer.parseInt(br.readLine());
        if(i == 0){
          min = v;
          continue;
        }

        if(max < v - min || i == 1){
          max = v - min;
        }
        if(min > v) min = v;
      }
      System.out.println(max);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}