import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    } main {
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int[] array = new int[num]; array new int[num] num for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int max = -2000000000; max -2000000000 2000000000 int min = array[0]; min array[0] array 0 for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        } int i = 1; int i = 1; i 1 i < num i num i++ i++ i {
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        } {
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        } if(max < array[i] - min){
                max = array[i] - min;
            } max < array[i] - min max array[i] - min array[i] array i min {
                max = array[i] - min;
            } max = array[i] - min max array[i] - min array[i] array i min if(min > array[i]){
                min = array[i];
            } min > array[i] min array[i] array i {
                min = array[i];
            } min = array[i] min array[i] array i System.out.println(max) System.out.println System.out System System.out max String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int num = sc.nextInt();
        int[] array = new int[num];
        for(int i = 0; i < num; i++){
            array[i] = sc.nextInt();
        }

        int max = -2000000000;
        int min = array[0];
        for(int i = 1; i < num; i++){
            if(max < array[i] - min){
                max = array[i] - min;
            }
            if(min > array[i]){
                min = array[i];
            }
        }
        System.out.println(max);
    }
}
