import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    }

    private static long max(long[] a){
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    }

    private static long max(long[] a){
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    }

} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc long[] a = new long[n]; a new long[n] n for(int i = 0;i < n;i++) a[i] = sc.nextLong(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = sc.nextLong(); a[i] = sc.nextLong() a[i] a i sc.nextLong() sc.nextLong sc sc.close() sc.close sc System.out.println(max(a)) System.out.println System.out System System.out max(a) max a String[] args args private static long max(long[] a){
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    } max {
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    } long max max ma = -1 ma -1 1 l = a.length; l a.length a a.length int in = 0; in 0 for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        } int i = 1; int i = 1; i 1 i < l i l i++ i++ i {
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        } {
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        } if(ma < a[i]){
                ma = a[i];
                in = i;
            } ma < a[i] ma a[i] a i {
                ma = a[i];
                in = i;
            } ma = a[i] ma a[i] a i in = i in i max = ma - a[0] max ma - a[0] ma a[0] a 0 for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        } int i = 1; int i = 1; i 1 i < l - 1 i l - 1 l 1 i++ i++ i {
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        } {
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        } if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            } i == in i in {
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            } ma = -1 ma -1 1 for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                } int j = in + 1; int j = in + 1; j in + 1 in 1 j < l j l j++ j++ j {
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                } {
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                } if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    } ma < a[j] ma a[j] a j {
                        ma = a[j];
                        in = j;
                    } ma = a[j] ma a[j] a j in = j in j if(max < ma - a[i]) max = ma - a[i]; max < ma - a[i] max ma - a[i] ma a[i] a i max = ma - a[i] max ma - a[i] ma a[i] a i return max; max long[] a a public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    }

    private static long max(long[] a){
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    }

} public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    }

    private static long max(long[] a){
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[n];
        for(int i = 0;i < n;i++) a[i] = sc.nextLong();
        sc.close();
        System.out.println(max(a));
    }

    private static long max(long[] a){
        long max,ma = -1,l = a.length;
        int in = 0;
        for(int i = 1;i < l;i++){
            if(ma < a[i]){
                ma = a[i];
                in = i;
            }
        }
        max = ma - a[0];
        for(int i = 1;i < l - 1;i++){
            if(i == in){
                ma = -1;
                for(int j = in + 1;j < l;j++){
                    if(ma < a[j]){
                        ma = a[j];
                        in = j;
                    }
                }
            }
            if(max < ma - a[i]) max = ma - a[i];
        }
        return max;
    }

}