public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int maxValue = 0;
        int maxLose = 0;
        for (int i = 0; i < n; i++) {
            int value = in.nextInt();
            if (maxValue - value > maxLose) {
                maxLose = maxValue - value;
            }
            if (value > maxValue) {
                maxValue = value;
            }
        }
        System.out.println(-maxLose);
    }