import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    }
    private static int maxDif(int[] arr){
        int min = arr[0],
            maxDif = arr[1] - min;
            if(min > arr[1])min = arr[1];

        for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    }
    private static int maxDif(int[] arr){
        int min = arr[0],
            maxDif = arr[1] - min;
            if(min > arr[1])min = arr[1];

        for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      }
} Main public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] arr = new int[n]; arr new int[n] n for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            arr[i] = Integer.parseInt(br.readLine());
        } {
            arr[i] = Integer.parseInt(br.readLine());
        } arr[i] = Integer.parseInt(br.readLine()) arr[i] arr i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br System.out.println(maxDif(arr)) System.out.println System.out System System.out maxDif(arr) maxDif arr String[] args args private static int maxDif(int[] arr){
        int min = arr[0],
            maxDif = arr[1] - min;
            if(min > arr[1])min = arr[1];

        for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      } maxDif {
        int min = arr[0],
            maxDif = arr[1] - min;
            if(min > arr[1])min = arr[1];

        for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      } int min = arr[0] min arr[0] arr 0 maxDif = arr[1] - min; maxDif arr[1] - min arr[1] arr 1 min if(min > arr[1])min = arr[1]; min > arr[1] min arr[1] arr 1 min = arr[1] min arr[1] arr 1 for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        } int i=2; int i=2; i 2 i<arr.length i arr.length arr arr.length i++ i++ i {
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        } {
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        } if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i]; arr[i] - min > maxDif arr[i] - min arr[i] arr i min maxDif maxDif = arr[i] - min maxDif arr[i] - min arr[i] arr i min if(arr[i] < min)min = arr[i]; arr[i] < min arr[i] arr i min min = arr[i] min arr[i] arr i return maxDif; maxDif int[] arr arr
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        for(int i=0;i<n;i++){
            arr[i] = Integer.parseInt(br.readLine());
        }

        System.out.println(maxDif(arr));
    }
    private static int maxDif(int[] arr){
        int min = arr[0],
            maxDif = arr[1] - min;
            if(min > arr[1])min = arr[1];

        for(int i=2; i<arr.length; i++){
            if(arr[i] - min > maxDif) maxDif = arr[i] - min;
            else if(arr[i] < min)min = arr[i];
        }
        return maxDif;
      }
}