using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;


namespace AizuOnlineJudge
{
    public class Program
    {
        /// <summary>
        /// 実行関数
        /// </summary>
        /// <param name="args"></param>
        public static void Main(string[] args)
        {
            // Programクラスの生成
            new Program().Anser2(new ConsoleInput(Console.In, ' '));
        }

        /// <summary>
        /// 答えの実行場所
        /// </summary>
        /// <param name="Input"></param>
        public void Anser1(ConsoleInput Input)
        {
            List<int> profitInfo = ProfitInfoList();

            var maxProfit = int.MinValue;

            for (int i = 0; i < profitInfo.Count; i++)
                for (int r = i + 1; r < profitInfo.Count; r++)
                {
                    if (maxProfit < profitInfo[r] - profitInfo[i])
                        maxProfit = profitInfo[r] - profitInfo[i];
                }

            Console.WriteLine(maxProfit);
            Console.ReadKey();
        }

        /// <summary>
        /// 答えの実行場所　アイズオンラインジャッジ　正答
        /// </summary>
        /// <param name="Input"></param>
        public void Anser2(ConsoleInput Input)
        {
            List<int> profitInfo = ProfitInfoList();

            // 最大利益格納用
            var maxProfit = int.MinValue;

            // 最少時利益格納用
            var tempMinProfit = int.MaxValue;


            for (int i = 0; i < profitInfo.Count - 1; i++)
            {
                // 通常計算 現在利益と次の利益の計算を行う
                if (maxProfit < profitInfo[i + 1] - profitInfo[i])
                    maxProfit = profitInfo[i + 1] - profitInfo[i];

                // 最少時利益計算　経過した時間の中で最も最少だった利益と次の利益を計算する
                if (maxProfit < profitInfo[i + 1] - tempMinProfit)
                    maxProfit = profitInfo[i + 1] - tempMinProfit;

                // 現在利益と最少時の利益を比較する
                if (profitInfo[i] < tempMinProfit)
                    tempMinProfit = profitInfo[i];
            }

            Console.WriteLine(maxProfit);
            Console.ReadKey();
        }

        /// <summary>
        /// 利益情報を取得する
        /// </summary>
        /// <returns>利益情報を格納したInteger型のList</returns>
        public  List<int> ProfitInfoList()
        {
            // ループ数の取得
            var loop = Convert.ToInt32(Console.ReadLine());

            // 利益情報格納リスト
            var profitInfo = new List<int>();

            for (int i = 0; i < loop; i++)
            {
                profitInfo.Add(Convert.ToInt32(Console.ReadLine()));
            }

            return profitInfo;
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader Stream;
        private char Separator = ' ';
        private Queue<string> InputStream;

        public ConsoleInput(System.IO.TextReader Stream, char Separator = ' ')
        {
            this.Separator = Separator;
            this.Stream = Stream;
            InputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if (InputStream.Count != 0)
                {
                    return InputStream.Dequeue();
                }

                string[] splitStrs = Stream.ReadLine().Split(Separator);

                for (int i = 0; i < splitStrs.Length; ++i)
                {
                    InputStream.Enqueue(splitStrs[i]);
                }

                return InputStream.Dequeue();
            }
        }

        public string ReadLine { get { return Stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }

        public string[] ReadStrArray(long N)
        {
            var inputStrArray = new string[N];
            for (long i = 0; i < N; ++i)
            {
                inputStrArray[i] = Read;
            }

            return inputStrArray;
        }

        public int[] ReadIntArray(long N)
        {
            var inputIntArray = new int[N];
            for (long i = 0; i < N; ++i)
            {
                inputIntArray[i] = ReadInt;
            }

            return inputIntArray;
        }

        public long[] ReadLongArray(long N)
        {
            var inputLongArray = new long[N];
            for (long i = 0; i < N; ++i)
            {
                inputLongArray[i] = ReadLong;
            }

            return inputLongArray;
        }
    }
}


Measured memory_bytes: 21880