import java.util.*;

/**
 * D
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    } main {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int max_v max_v min_v; min_v int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int array[] = new int[n]; array new int[n] n for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc sc.close() sc.close sc max_v = array[1] - array[0] max_v array[1] - array[0] array[1] array 1 array[0] array 0 min_v = array[0] min_v array[0] array 0 for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        } int i=1; int i=1; i 1 i<n i n i++ i++ i {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        } {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        } if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            } array[i] - min_v > max_v array[i] - min_v array[i] array i min_v max_v {
                max_v = array[i] - min_v;
            } max_v = array[i] - min_v max_v array[i] - min_v array[i] array i min_v if(array[i] < min_v) {
                min_v = array[i];
            } array[i] < min_v array[i] array i min_v {
                min_v = array[i];
            } min_v = array[i] min_v array[i] array i System.out.println(max_v) System.out.println System.out System System.out max_v String[] args args public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    }
} Main
import java.util.*;

/**
 * D
 */
public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int max_v, min_v;
        int n = sc.nextInt();

        int array[] = new int[n];

        for(int i=0; i<n; i++) {
            array[i] = sc.nextInt();
        }

        sc.close();

        max_v = array[1] - array[0];
        min_v = array[0];

        for(int i=1; i<n; i++) {

            if(array[i] - min_v > max_v) {
                max_v = array[i] - min_v;
            }

            if(array[i] < min_v) {
                min_v = array[i];
            }

        }

        System.out.println(max_v);

    }
}
