import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.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 public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.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 sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    }
    System.out.println(maxv);
  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    }
    System.out.println(maxv);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n int maxv = -1000000000; maxv -1000000000 1000000000 a[0] = sc.nextInt() a[0] a 0 sc.nextInt() sc.nextInt sc int minv = a[0]; minv a[0] a 0 for(int i = 1; i<n; i++){
      a[i] = sc.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] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    } {
      a[i] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc 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 public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    }
    System.out.println(maxv);
  }
} public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    }
    System.out.println(maxv);
  }
} Main
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int maxv = -1000000000;
    a[0] = sc.nextInt();
    int minv = a[0];
    for(int i = 1; i<n; i++){
      a[i] = sc.nextInt();
      maxv = Math.max(maxv, a[i]-minv);
      minv = Math.min(minv,a[i]);
    }
    System.out.println(maxv);
  }
}