import java.io.*;

class Main{
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public static void main(String[] args) throws IOException{
                int n = Integer.parseInt(br.readLine());
                int[] A = new int[n];
                int max = 0;
                int dis = 0;
                for(int i=0; i<n; i++)
                        A[i] = Integer.parseInt(br.readLine());
                dis = A[n-1]-A[n-2];
                for(int i=n-1; i>0; i--){
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                }
                System.out.println(dis);
        }
} import java.io.*; io.* java class Main{
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public static void main(String[] args) throws IOException{
                int n = Integer.parseInt(br.readLine());
                int[] A = new int[n];
                int max = 0;
                int dis = 0;
                for(int i=0; i<n; i++)
                        A[i] = Integer.parseInt(br.readLine());
                dis = A[n-1]-A[n-2];
                for(int i=n-1; i>0; i--){
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                }
                System.out.println(dis);
        }
} Main private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public static void main(String[] args) throws IOException{
                int n = Integer.parseInt(br.readLine());
                int[] A = new int[n];
                int max = 0;
                int dis = 0;
                for(int i=0; i<n; i++)
                        A[i] = Integer.parseInt(br.readLine());
                dis = A[n-1]-A[n-2];
                for(int i=n-1; i>0; i--){
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                }
                System.out.println(dis);
        } main {
                int n = Integer.parseInt(br.readLine());
                int[] A = new int[n];
                int max = 0;
                int dis = 0;
                for(int i=0; i<n; i++)
                        A[i] = Integer.parseInt(br.readLine());
                dis = A[n-1]-A[n-2];
                for(int i=n-1; i>0; i--){
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                }
                System.out.println(dis);
        } int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] A = new int[n]; A new int[n] n int max = 0; max 0 int dis = 0; dis 0 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] A i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br dis = A[n-1]-A[n-2] dis A[n-1]-A[n-2] A[n-1] A n-1 n 1 A[n-2] A n-2 n 2 for(int i=n-1; i>0; i--){
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                } int i=n-1; int i=n-1; i n-1 n 1 i>0 i 0 i-- i-- i {
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                } {
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                } if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        } A[i] > max A[i] A i max {
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        } max = A[i] max A[i] A i for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                } int j=i-1; int j=i-1; j i-1 i 1 j>=0 j 0 j-- j-- j {
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                } {
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                } int t = A[i]-A[j]; t A[i]-A[j] A[i] A i A[j] A j if(t>dis)
                                                dis = t; t>dis t dis dis = t dis t System.out.println(dis) System.out.println System.out System System.out dis String[] args args
import java.io.*;

class Main{
        private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        public static void main(String[] args) throws IOException{
                int n = Integer.parseInt(br.readLine());
                int[] A = new int[n];
                int max = 0;
                int dis = 0;
                for(int i=0; i<n; i++)
                        A[i] = Integer.parseInt(br.readLine());
                dis = A[n-1]-A[n-2];
                for(int i=n-1; i>0; i--){
                        if(A[i] > max){
                                max = A[i];
                                for(int j=i-1; j>=0; j--){
                                        int t = A[i]-A[j];
                                        if(t>dis)
                                                dis = t;
                                }
                        }
                }
                System.out.println(dis);
        }
}