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



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    }

    
}
 import java.io.*; io.* java import java.util.*; util.* java public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    }

    
} Main public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String str; str str = br.readLine() str br.readLine() br.readLine br int x = Integer.parseInt(str.trim()); x Integer.parseInt(str.trim()) Integer.parseInt Integer str.trim() str.trim str int[] line = new int[x]; line new int[x] x for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        } int i=0; int i=0; i 0 i<x i x i++ i++ i {
            line[i] = Integer.parseInt(br.readLine());
        } {
            line[i] = Integer.parseInt(br.readLine());
        } line[i] = Integer.parseInt(br.readLine()) line[i] line i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int ans = -1000000000; ans -1000000000 1000000000 int Ri = line[0]; Ri line[0] line 0 for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        } int i=1; int i=1; i 1 i<x i x i++ i++ i {
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        } {
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        } if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            } line[i] - Ri >ans line[i] - Ri line[i] line i Ri ans {
                ans = line[i] - Ri;
            } ans = line[i] - Ri ans line[i] - Ri line[i] line i Ri if(Ri > line[i]){
                Ri = line[i];
            } Ri > line[i] Ri line[i] line i {
                Ri = line[i];
            } Ri = line[i] Ri line[i] line i System.out.println(ans) System.out.println System.out System System.out ans br.close() br.close br String[] args args public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    }

    
} public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    }

    
} Main
import java.io.*;
import java.util.*;



public class Main{
    public static void main(String[] args)throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str;
                    
        str = br.readLine();
        int x = Integer.parseInt(str.trim());
        int[] line = new int[x];

        for(int i=0;i<x;i++){
            line[i] = Integer.parseInt(br.readLine());
        }

        int ans = -1000000000;
        int Ri = line[0];
        for(int i=1;i<x;i++){
            if(line[i] - Ri >ans){
                ans = line[i] - Ri;
            }
            if(Ri > line[i]){
                Ri = line[i];
            }

        }

        System.out.println(ans);

        br.close();
    }

    
}

