import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] num_list = new int[n];
    for (int i = 0; i < n; i++){
      num_list[i] = sc.nextInt();
    }
    max_value(num_list, n);
  }

  public static void max_value(int[] lst, int n){
    int maxval = -2000000000;
    int minval = lst[0];
    for (int i = 0; i < n - 1; i++){
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    }
    System.out.println(maxval);
  }
} import java.util.*; util.* java class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] num_list = new int[n];
    for (int i = 0; i < n; i++){
      num_list[i] = sc.nextInt();
    }
    max_value(num_list, n);
  }

  public static void max_value(int[] lst, int n){
    int maxval = -2000000000;
    int minval = lst[0];
    for (int i = 0; i < n - 1; i++){
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    }
    System.out.println(maxval);
  }
} Main public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] num_list = new int[n];
    for (int i = 0; i < n; i++){
      num_list[i] = sc.nextInt();
    }
    max_value(num_list, n);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] num_list = new int[n];
    for (int i = 0; i < n; i++){
      num_list[i] = sc.nextInt();
    }
    max_value(num_list, n);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] num_list = new int[n]; num_list new int[n] n for (int i = 0; i < n; i++){
      num_list[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      num_list[i] = sc.nextInt();
    } {
      num_list[i] = sc.nextInt();
    } num_list[i] = sc.nextInt() num_list[i] num_list i sc.nextInt() sc.nextInt sc max_value(num_list, n) max_value num_list n String[] args args public static void max_value(int[] lst, int n){
    int maxval = -2000000000;
    int minval = lst[0];
    for (int i = 0; i < n - 1; i++){
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    }
    System.out.println(maxval);
  } max_value {
    int maxval = -2000000000;
    int minval = lst[0];
    for (int i = 0; i < n - 1; i++){
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    }
    System.out.println(maxval);
  } int maxval = -2000000000; maxval -2000000000 2000000000 int minval = lst[0]; minval lst[0] lst 0 for (int i = 0; i < n - 1; i++){
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    } int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    } {
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    } maxval = Math.max(maxval, lst[i + 1] - minval) maxval Math.max(maxval, lst[i + 1] - minval) Math.max Math maxval lst[i + 1] - minval lst[i + 1] lst i + 1 i 1 minval minval = Math.min(minval, lst[i + 1]) minval Math.min(minval, lst[i + 1]) Math.min Math minval lst[i + 1] lst i + 1 i 1 System.out.println(maxval) System.out.println System.out System System.out maxval int[] lst lst int n n
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] num_list = new int[n];
    for (int i = 0; i < n; i++){
      num_list[i] = sc.nextInt();
    }
    max_value(num_list, n);
  }

  public static void max_value(int[] lst, int n){
    int maxval = -2000000000;
    int minval = lst[0];
    for (int i = 0; i < n - 1; i++){
      maxval = Math.max(maxval, lst[i + 1] - minval);
      minval = Math.min(minval, lst[i + 1]);
    }
    System.out.println(maxval);
  }
}
