import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    int maxv = -2000000000;
    int minv = stdIn.nextInt();
    for (int i = 1; i < n; i++) {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    }
    System.out.println(maxv);
  }
} import java.util.Scanner; Scanner java.util class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    int maxv = -2000000000;
    int minv = stdIn.nextInt();
    for (int i = 1; i < n; i++) {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    }
    System.out.println(maxv);
  }
} Main public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    int maxv = -2000000000;
    int minv = stdIn.nextInt();
    for (int i = 1; i < n; i++) {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    }
    System.out.println(maxv);
  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    int maxv = -2000000000;
    int minv = stdIn.nextInt();
    for (int i = 1; i < n; i++) {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    }
    System.out.println(maxv);
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] a = new int[n]; a new int[n] n int maxv = -2000000000; maxv -2000000000 2000000000 int minv = stdIn.nextInt(); minv stdIn.nextInt() stdIn.nextInt stdIn for (int i = 1; i < n; i++) {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    } {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    } a[i] = stdIn.nextInt() a[i] a i stdIn.nextInt() stdIn.nextInt stdIn maxv = Math.max(maxv, a[i] - minv) maxv Math.max(maxv, a[i] - minv) Math.max Math maxv a[i] - minv a[i] a i minv minv = Math.min(minv, a[i]) minv Math.min(minv, a[i]) Math.min Math minv a[i] a i System.out.println(maxv) System.out.println System.out System System.out maxv String[] args args
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    int maxv = -2000000000;
    int minv = stdIn.nextInt();
    for (int i = 1; i < n; i++) {
      a[i] = stdIn.nextInt();
      maxv = Math.max(maxv, a[i] - minv);
      minv = Math.min(minv, a[i]);
    }
    System.out.println(maxv);
  }
}