import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        int r0 = Integer.parseInt(sc.next());
        int r1 = Integer.parseInt(sc.next());

        int max = r1-r0;
        int min = Math.min(r0,r1);

        for(int i = 2; i < n; i++){
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        }
        
        System.out.println(max);
    }
} import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        int r0 = Integer.parseInt(sc.next());
        int r1 = Integer.parseInt(sc.next());

        int max = r1-r0;
        int min = Math.min(r0,r1);

        for(int i = 2; i < n; i++){
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        }
        
        System.out.println(max);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        int r0 = Integer.parseInt(sc.next());
        int r1 = Integer.parseInt(sc.next());

        int max = r1-r0;
        int min = Math.min(r0,r1);

        for(int i = 2; i < n; i++){
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        }
        
        System.out.println(max);
    } main {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        int r0 = Integer.parseInt(sc.next());
        int r1 = Integer.parseInt(sc.next());

        int max = r1-r0;
        int min = Math.min(r0,r1);

        for(int i = 2; i < n; i++){
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        }
        
        System.out.println(max);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.next()); n Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r0 = Integer.parseInt(sc.next()); r0 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int r1 = Integer.parseInt(sc.next()); r1 Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int max = r1-r0; max r1-r0 r1 r0 int min = Math.min(r0,r1); min Math.min(r0,r1) Math.min Math r0 r1 for(int i = 2; i < n; i++){
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        } int i = 2; int i = 2; i 2 i < n i n i++ i++ i {
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        } {
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        } int r = Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc max = Math.max(max, r - min) max Math.max(max, r - min) Math.max Math max r - min r min min = Math.min(min,r) min Math.min(min,r) Math.min Math min r System.out.println(max) System.out.println System.out System System.out max String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());

        int r0 = Integer.parseInt(sc.next());
        int r1 = Integer.parseInt(sc.next());

        int max = r1-r0;
        int min = Math.min(r0,r1);

        for(int i = 2; i < n; i++){
            int r = Integer.parseInt(sc.next());
            max = Math.max(max, r - min);
            min = Math.min(min,r);
        }
        
        System.out.println(max);
    }
}
