import java.util.Scanner;

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

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

  }
} 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[] R = new int[n];
    for(int i = 0; i < n; i++) {
      R[i] = sc.nextInt();
    }

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

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

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

  } main {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] R = new int[n];
    for(int i = 0; i < n; i++) {
      R[i] = sc.nextInt();
    }

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] R = new int[n]; R new int[n] n for(int i = 0; i < n; i++) {
      R[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      R[i] = sc.nextInt();
    } {
      R[i] = sc.nextInt();
    } R[i] = sc.nextInt() R[i] R i sc.nextInt() sc.nextInt sc int minv = 2000000000; minv 2000000000 int maxp = -2000000000; maxp -2000000000 2000000000 int t; t for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    } {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    } if (R[i - 1] < minv)  minv = R[i - 1]; R[i - 1] < minv R[i - 1] R i - 1 i 1 minv minv = R[i - 1] minv R[i - 1] R i - 1 i 1 t = R[i] - minv t R[i] - minv R[i] R i minv if(t > maxp)  maxp = t; t > maxp t maxp maxp = t maxp t System.out.println(maxp) System.out.println System.out System System.out maxp String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] R = new int[n];
    for(int i = 0; i < n; i++) {
      R[i] = sc.nextInt();
    }

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

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

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

  }
} 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[] R = new int[n];
    for(int i = 0; i < n; i++) {
      R[i] = sc.nextInt();
    }

    int minv = 2000000000;
    int maxp = -2000000000;
    int t;
    for(int i = 1; i < n; i++) {
      if (R[i - 1] < minv)  minv = R[i - 1];
      t = R[i] - minv;
      if(t > maxp)  maxp = t;
    }

    System.out.println(maxp);

  }
}