import java.io.*;

class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int it = Integer.parseInt(str);
        String[] strarr = new String[it];
        for(int i=0; i < it; i++) {
            strarr[i] = br.readLine();
        }
        
        int max = -1000000001;
        int min = Integer.parseInt(strarr[0]);
        for(int i=1; i < it; i++) {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        }
        
        System.out.println(max);
    }
    
} import java.io.*; io.* java class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int it = Integer.parseInt(str);
        String[] strarr = new String[it];
        for(int i=0; i < it; i++) {
            strarr[i] = br.readLine();
        }
        
        int max = -1000000001;
        int min = Integer.parseInt(strarr[0]);
        for(int i=1; i < it; i++) {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        }
        
        System.out.println(max);
    }
    
} Main public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int it = Integer.parseInt(str);
        String[] strarr = new String[it];
        for(int i=0; i < it; i++) {
            strarr[i] = br.readLine();
        }
        
        int max = -1000000001;
        int min = Integer.parseInt(strarr[0]);
        for(int i=1; i < it; i++) {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        }
        
        System.out.println(max);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int it = Integer.parseInt(str);
        String[] strarr = new String[it];
        for(int i=0; i < it; i++) {
            strarr[i] = br.readLine();
        }
        
        int max = -1000000001;
        int min = Integer.parseInt(strarr[0]);
        for(int i=1; i < it; i++) {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        }
        
        System.out.println(max);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str = br.readLine(); str br.readLine() br.readLine br int it = Integer.parseInt(str); it Integer.parseInt(str) Integer.parseInt Integer str String[] strarr = new String[it]; strarr new String[it] it for(int i=0; i < it; i++) {
            strarr[i] = br.readLine();
        } int i=0; int i=0; i 0 i < it i it i++ i++ i {
            strarr[i] = br.readLine();
        } {
            strarr[i] = br.readLine();
        } strarr[i] = br.readLine() strarr[i] strarr i br.readLine() br.readLine br int max = -1000000001; max -1000000001 1000000001 int min = Integer.parseInt(strarr[0]); min Integer.parseInt(strarr[0]) Integer.parseInt Integer strarr[0] strarr 0 for(int i=1; i < it; i++) {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        } int i=1; int i=1; i 1 i < it i it i++ i++ i {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        } {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        } max = Math.max(max, Integer.parseInt(strarr[i])-min) max Math.max(max, Integer.parseInt(strarr[i])-min) Math.max Math max Integer.parseInt(strarr[i])-min Integer.parseInt(strarr[i]) Integer.parseInt Integer strarr[i] strarr i min min = Math.min(min, Integer.parseInt(strarr[i])) min Math.min(min, Integer.parseInt(strarr[i])) Math.min Math min Integer.parseInt(strarr[i]) Integer.parseInt Integer strarr[i] strarr i System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.*;

class Main {
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int it = Integer.parseInt(str);
        String[] strarr = new String[it];
        for(int i=0; i < it; i++) {
            strarr[i] = br.readLine();
        }
        
        int max = -1000000001;
        int min = Integer.parseInt(strarr[0]);
        for(int i=1; i < it; i++) {
            max = Math.max(max, Integer.parseInt(strarr[i])-min);
            min = Math.min(min, Integer.parseInt(strarr[i]));
        }
        
        System.out.println(max);
    }
    
}
