import java.util.Scanner;

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

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; i++){
            list[i] = scan.nextInt();
        }

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; i++){
            list[i] = scan.nextInt();
        }

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; i++){
            list[i] = scan.nextInt();
        }

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] list = new int[n]; list new int[n] n for(int i=0; i<n; i++){
            list[i] = scan.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            list[i] = scan.nextInt();
        } {
            list[i] = scan.nextInt();
        } list[i] = scan.nextInt() list[i] list i scan.nextInt() scan.nextInt scan int minindex; minindex int min; min int max = list[n-1]; max list[n-1] list n-1 n 1 int diff = max-list[0]; diff max-list[0] max list[0] list 0 for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        } int m=n; int m=n; m n m>0 m 0 {
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        } {
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        } if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            } m==1 m 1 {
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            } if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                } diff<list[1]-list[0] diff list[1]-list[0] list[1] list 1 list[0] list 0 {
                    diff = list[1]-list[0];
                } diff = list[1]-list[0] diff list[1]-list[0] list[1] list 1 list[0] list 0 m-- m minindex = 0 minindex 0 min = list[0] min list[0] list 0 for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            } int i = 0; int i = 0; i 0 i < m i m i++ i++ i {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            } {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            } if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                } list[i] < min list[i] list i min {
                    minindex = i;
                    min = list[i];
                } minindex = i minindex i min = list[i] min list[i] list i if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            } minindex == m-1 minindex m-1 m 1 {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                } diff<min-list[m-2] diff min-list[m-2] min list[m-2] list m-2 m 2 {
                    diff = min-list[m-2];
                } diff = min-list[m-2] diff min-list[m-2] min list[m-2] list m-2 m 2 m-- m {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            } max = list[minindex+1] max list[minindex+1] list minindex+1 minindex 1 for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                } int i = minindex + 1; int i = minindex + 1; i minindex + 1 minindex 1 i < n i n i++ i++ i {
                    if (list[i] > max) {
                        max = list[i];
                    }
                } {
                    if (list[i] > max) {
                        max = list[i];
                    }
                } if (list[i] > max) {
                        max = list[i];
                    } list[i] > max list[i] list i max {
                        max = list[i];
                    } max = list[i] max list[i] list i if(diff<max-min){
                    diff = max-min;
                } diff<max-min diff max-min max min {
                    diff = max-min;
                } diff = max-min diff max-min max min m = minindex m minindex System.out.println(diff) System.out.println System.out System System.out diff String[] args args public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; i++){
            list[i] = scan.nextInt();
        }

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    }
} public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] list = new int[n];
        for(int i=0; i<n; i++){
            list[i] = scan.nextInt();
        }

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    }
} Main
import java.util.Scanner;

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

        int minindex;
        int min;
        int max = list[n-1];
        int diff = max-list[0];
        for(int m=n; m>0; ){
            if(m==1){
                if(diff<list[1]-list[0]){
                    diff = list[1]-list[0];
                }
                m--;
            }
            minindex = 0;
            min = list[0];
            for (int i = 0; i < m; i++) {
                if (list[i] < min) {
                    minindex = i;
                    min = list[i];
                }
            }
            if (minindex == m-1) {
                if(diff<min-list[m-2]){
                    diff = min-list[m-2];
                }
                m--;
            } else {
                max = list[minindex+1];
                for (int i = minindex + 1; i < n; i++) {
                    if (list[i] > max) {
                        max = list[i];
                    }
                }
                if(diff<max-min){
                    diff = max-min;
                }
                m = minindex;
            }
        }
        System.out.println(diff);
    }
}

