import java.io.*;
import java.util.*;

class Main {

    static int[] a;
    static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n];
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); }
        int mini=1000000000;
        int max=-1000000000;
        int max_index=1;
        for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        }System.out.println(max);
    }
    
} import java.io.*; io.* java import java.util.*; util.* java class Main {

    static int[] a;
    static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n];
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); }
        int mini=1000000000;
        int max=-1000000000;
        int max_index=1;
        for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        }System.out.println(max);
    }
    
} Main static int[] a; a static int n; n public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n];
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); }
        int mini=1000000000;
        int max=-1000000000;
        int max_index=1;
        for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        }System.out.println(max);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n];
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); }
        int mini=1000000000;
        int max=-1000000000;
        int max_index=1;
        for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        }System.out.println(max);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) n=Integer.parseInt(br.readLine()) n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br a=new int[n] a new int[n] n for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); } int i=0; int i=0; i 0 i<n i n i++ i++ i { a[i]=Integer.parseInt(br.readLine()); } { a[i]=Integer.parseInt(br.readLine()); } a[i]=Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int mini=1000000000; mini 1000000000 int max=-1000000000; max -1000000000 1000000000 int max_index=1; max_index 1 for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        } {
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        } if(mini>a[i]){ mini=a[i]; } mini>a[i] mini a[i] a i { mini=a[i]; } mini=a[i] mini a[i] a i if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; } i<n-1 && max<a[i+1]-mini i<n-1 i n-1 n 1 max<a[i+1]-mini max a[i+1]-mini a[i+1] a i+1 i 1 mini { max=a[i+1]-mini; } max=a[i+1]-mini max a[i+1]-mini a[i+1] a i+1 i 1 mini System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.*;
import java.util.*;

class Main {

    static int[] a;
    static int n;

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        n=Integer.parseInt(br.readLine());
        a=new int[n];
        for(int i=0;i<n;i++){ a[i]=Integer.parseInt(br.readLine()); }
        int mini=1000000000;
        int max=-1000000000;
        int max_index=1;
        for(int i=0;i<n;i++){
            if(mini>a[i]){ mini=a[i]; }
            if(i<n-1 && max<a[i+1]-mini){ max=a[i+1]-mini; }
        }System.out.println(max);
    }
    
}