import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        int r = Integer.parseInt(br.readLine());
        int rm = r;
        r = Integer.parseInt(br.readLine());
        int ans = r-rm;
        if(r<rm) rm = r;
        for(int i = 2; i<n; i++){
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        }
        System.out.println(ans);
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
    public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        int r = Integer.parseInt(br.readLine());
        int rm = r;
        r = Integer.parseInt(br.readLine());
        int ans = r-rm;
        if(r<rm) rm = r;
        for(int i = 2; i<n; i++){
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        }
        System.out.println(ans);
    }
} Main public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        int r = Integer.parseInt(br.readLine());
        int rm = r;
        r = Integer.parseInt(br.readLine());
        int ans = r-rm;
        if(r<rm) rm = r;
        for(int i = 2; i<n; i++){
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        }
        System.out.println(ans);
    } main {
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        int r = Integer.parseInt(br.readLine());
        int rm = r;
        r = Integer.parseInt(br.readLine());
        int ans = r-rm;
        if(r<rm) rm = r;
        for(int i = 2; i<n; i++){
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        }
        System.out.println(ans);
    } final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) final int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int r = Integer.parseInt(br.readLine()); r Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int rm = r; rm r r = Integer.parseInt(br.readLine()) r Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int ans = r-rm; ans r-rm r rm if(r<rm) rm = r; r<rm r rm rm = r rm r for(int i = 2; i<n; i++){
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        } int i = 2; int i = 2; i 2 i<n i n i++ i++ i {
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        } {
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        } r = Integer.parseInt(br.readLine()) r Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br if(ans<r-rm) ans = r-rm; ans<r-rm ans r-rm r rm ans = r-rm ans r-rm r rm if(r<rm) rm = r; r<rm r rm rm = r rm r System.out.println(ans) System.out.println System.out System System.out ans String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
    public static void main(String[] args) throws IOException{
        final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        final int n = Integer.parseInt(br.readLine());
        int r = Integer.parseInt(br.readLine());
        int rm = r;
        r = Integer.parseInt(br.readLine());
        int ans = r-rm;
        if(r<rm) rm = r;
        for(int i = 2; i<n; i++){
            r = Integer.parseInt(br.readLine());
            if(ans<r-rm) ans = r-rm;
            if(r<rm) rm = r;
        }
        System.out.println(ans);
    }
}