import java.util.Scanner;
import java.lang.Math;
class Main{

  public static void main(String args[]){

    Scanner stdIn=new Scanner(System.in);
    int x=stdIn.nextInt();
    long[] a=new long[x];
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    long minv=a[0];
    long maxv=-999999999;

    for(int i=1; i<x; i++){
        maxv=Math.max(maxv,a[i]-minv);
        minv=Math.min(minv,a[i]);
    }

    System.out.println(maxv);
  }
}
 import java.util.Scanner; Scanner java.util import java.lang.Math; Math java.lang class Main{

  public static void main(String args[]){

    Scanner stdIn=new Scanner(System.in);
    int x=stdIn.nextInt();
    long[] a=new long[x];
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    long minv=a[0];
    long maxv=-999999999;

    for(int i=1; i<x; i++){
        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 x=stdIn.nextInt();
    long[] a=new long[x];
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    long minv=a[0];
    long maxv=-999999999;

    for(int i=1; i<x; i++){
        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 x=stdIn.nextInt();
    long[] a=new long[x];
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    long minv=a[0];
    long maxv=-999999999;

    for(int i=1; i<x; i++){
        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 x=stdIn.nextInt(); x stdIn.nextInt() stdIn.nextInt stdIn long[] a=new long[x]; a new long[x] x for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    } int i=0; int i=0; i 0 i<x i x i++ i++ i {
        a[i]=stdIn.nextLong();
    } {
        a[i]=stdIn.nextLong();
    } a[i]=stdIn.nextLong() a[i] a i stdIn.nextLong() stdIn.nextLong stdIn long minv=a[0]; minv a[0] a 0 long maxv=-999999999; maxv -999999999 999999999 for(int i=1; i<x; i++){
        maxv=Math.max(maxv,a[i]-minv);
        minv=Math.min(minv,a[i]);
    } int i=1; int i=1; i 1 i<x i x i++ i++ i {
        maxv=Math.max(maxv,a[i]-minv);
        minv=Math.min(minv,a[i]);
    } {
        maxv=Math.max(maxv,a[i]-minv);
        minv=Math.min(minv,a[i]);
    } 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;
import java.lang.Math;
class Main{

  public static void main(String args[]){

    Scanner stdIn=new Scanner(System.in);
    int x=stdIn.nextInt();
    long[] a=new long[x];
    for(int i=0;i<x;i++){
        a[i]=stdIn.nextLong();
    }
    long minv=a[0];
    long maxv=-999999999;

    for(int i=1; i<x; i++){
        maxv=Math.max(maxv,a[i]-minv);
        minv=Math.min(minv,a[i]);
    }

    System.out.println(maxv);
  }
}

