import java.io.*;

class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
} import java.io.*; io.* java class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
} Main public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        } maxv {
            if(x >= y){
                return x;
            }else{
                return y;
            }
        } if(x >= y){
                return x;
            }else{
                return y;
            } x >= y x y {
                return x;
            } return x; x {
                return y;
            } return y; y int x x int y y public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        } minv {
            if(x <= y){
                return x;
            }else{
                return y;
            }
        } if(x <= y){
                return x;
            }else{
                return y;
            } x <= y x y {
                return x;
            } return x; x {
                return y;
            } return y; y int x x int y y public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    } main {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    } BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); reader new BufferedReader(new InputStreamReader(System.in)) try {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        } IOException e {
            //TODO: handle exception
            System.out.println(e);
        } System.out.println(e) System.out.println System.out System System.out e {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } int N = Integer.parseInt(reader.readLine()); N Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader int[] a = new int[N]; a new int[N] N for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    } int i = 0; int i = 0; i 0 i < N i N i ++ i ++ i {
                        a[i] = Integer.parseInt(reader.readLine());
                    } {
                        a[i] = Integer.parseInt(reader.readLine());
                    } a[i] = Integer.parseInt(reader.readLine()) a[i] a i Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader int min = a[0]; min a[0] a 0 int max = a[1] - a[0]; max a[1] - a[0] a[1] a 1 a[0] a 0 for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    } int i = 0; int i = 0; i 0 i < (N- 1) i (N- 1) N 1 i++ i++ i {
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    } {
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    } min = minv(min, a[i]) min minv(min, a[i]) minv min a[i] a i max = maxv(max, (a[i + 1] - min)) max maxv(max, (a[i + 1] - min)) maxv max (a[i + 1] - min) a[i + 1] a i + 1 i 1 min System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.io.*;

class Main{
    
        public static int maxv(int x, int y){
            if(x >= y){
                return x;
            }else{
                return y;
            }
        }

        public static int minv(int x, int y){
            if(x <= y){
                return x;
            }else{
                return y;
            }
        }

    public static void main(String[] args){

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {       
                    int N = Integer.parseInt(reader.readLine());;
                    

                    int[] a = new int[N];

                    for(int i = 0; i < N; i ++){
                        a[i] = Integer.parseInt(reader.readLine());
                    }

                    int min = a[0];
                    int max = a[1] - a[0];

                    for(int i = 0; i < (N- 1); i++){
                        min = minv(min, a[i]);
                        max = maxv(max, (a[i + 1] - min));
                    }

                    System.out.println(max);
                            
        } catch (IOException e) {
            //TODO: handle exception
            System.out.println(e);
        }
    }
}