using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//using System.Threading.Tasks;

namespace Maximum_Profit
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int max = int.MinValue;
            int min = int.Parse(Console.ReadLine());
            int now;
            for (int i = 0; i < n - 1; ++i)
            {
                now = int.Parse(Console.ReadLine());
                max = max > now - min ? max : now - min;
                min = min > now ? now : min;
            }
            Console.WriteLine(max);
        }
    }

    public static class My_Algorithm
    {
        //?????\????????? Insertion_Sort
        public static void Insertion_Sort(ref int[] array)
        {
            for (int i = 1; i < array.Length; ++i)
            {
                int v = array[i];
                int j = i - 1;
                while (j >= 0 && array[j] > v)
                {
                    array[j + 1] = array[j];
                    --j;
                }
                array[j + 1] = v;
                //for (int k = 0; k < array.Length - 1; ++k) Console.Write("{0} ", array[k]);
                //Console.WriteLine(array[array.Length - 1]);
            }
        }

        //?????§??¬?´???° Greatest_Common_Divisor
        public static int GCD(int m, int n)
        {
            if ((m == 0) || (n == 0)) return 0;
            while ((m != 0) && (n != 0))
            {
                if (m > n) m = m % n;
                else n = n % m;
            }
            if (m == 0) return n;
            else return m;
        }
        public static long GCD(long m, long n)
        {
            if ((m == 0) || (n == 0)) return 0;
            while ((m != 0) && (n != 0))
            {
                if (m > n) m = m % n;
                else n = n % m;
            }
            if (m == 0) return n;
            else return m;
        }
        //????°???¬?????° Least_Common_Multiple
        public static int LCM(int m, int n)
        {
            if ((m == 0) || (n == 0)) return 0;
            return m * n / My_Algorithm.GCD(m, n);
        }
        public static long LCM(long m, long n)
        {
            if ((m == 0) || (n == 0)) return 0;
            return m * n / My_Algorithm.GCD(m, n);
        }

        //??¨???????????????????????? Eratosthenes's_Sieve
        public static List<int> Prime_Number_List(int n)
        {
            bool k;
            List<int> list = new List<int>();
            list.Add(2);
            for (int i = 3; i <= n; i += 2)
            {
                k = true;
                for (int j = 3; j * j <= i; j += 2)
                {
                    if (i % j == 0)
                    {
                        k = false;
                        break;
                    }
                }
                if (k) list.Add(i);
            }
            return list;
        }
        public static List<long> Prime_Number_List(long n)
        {
            bool k;
            List<long> list = new List<long>();
            list.Add(2);
            for (int i = 3; i <= n; i += 2)
            {
                k = true;
                for (int j = 3; j * j <= i; j += 2)
                {
                    if (i % j == 0)
                    {
                        k = false;
                        break;
                    }
                }
                if (k) list.Add(i);
            }
            return list;
        }

        //?´???°???????????? Is_Prime?
        public static bool Is_Prime(int n)
        {
            if (n < 2) return false;
            if (n == 2) return true;
            if (n % 2 == 0) return false;
            for (int i = 3; i < n; ++i) if (n % i == 0) return false;
            return true;
        }
        public static bool Is_Prime(long n)
        {
            if (n < 2) return false;
            if (n == 2) return true;
            if (n % 2 == 0) return false;
            for (int i = 3; i < n; ++i) if (n % i == 0) return false;
            return true;
        }

    }
}


Measured memory_bytes: 9160