

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    }
    public static int maximumProfit(int[] arr) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        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();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    }
    public static int maximumProfit(int[] arr) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        return max;
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] arr = new int[N]; arr new int[N] N for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            arr[i] = sc.nextInt();
        } {
            arr[i] = sc.nextInt();
        } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int res = maximumProfit(arr); res maximumProfit(arr) maximumProfit arr System.out.println(res) System.out.println System.out System System.out res String[] args args public static int maximumProfit(int[] arr) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        return max;
    } maximumProfit {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        return max;
    } int max = Integer.MIN_VALUE; max Integer.MIN_VALUE Integer Integer.MIN_VALUE int min = Integer.MAX_VALUE; min Integer.MAX_VALUE Integer Integer.MAX_VALUE for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        } int i = 1; int i = 1; i 1 i < arr.length i arr.length arr arr.length i++ i++ i {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        } {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        } min = Math.min(min, arr[i-1]) min Math.min(min, arr[i-1]) Math.min Math min arr[i-1] arr i-1 i 1 max = Math.max(max, arr[i]-min) max Math.max(max, arr[i]-min) Math.max Math max arr[i]-min arr[i] arr i min return max; max int[] arr arr public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    }
    public static int maximumProfit(int[] arr) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        return max;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    }
    public static int maximumProfit(int[] arr) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        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();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++)
        {
            arr[i] = sc.nextInt();
        }
        int res = maximumProfit(arr);
        System.out.println(res);
    }
    public static int maximumProfit(int[] arr) {
        int max = Integer.MIN_VALUE;
        int min = Integer.MAX_VALUE;

        for(int i = 1; i < arr.length; i++)
        {
            min = Math.min(min, arr[i-1]);
            max = Math.max(max, arr[i]-min);
        }
        return max;
    }
}

