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);
        }
    }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz