#!/usr/bin/ruby
# -*- coding: utf-8 -*-
=begin
ALDS1_1-D

Getting Started - Maximum Profit
????????¶??? : 1 sec, ?????¢?????¶??? : 65536 KB
?????§?????????

FX????????§????????°?????????????????¨????????????????????¨??§????????????????????????????????¨?????§????????????????????°????????????100???????????? 1000???????????????????????????????????? 1?????? 108???????????£??????????£??????¨???(108??? - 100???) \times 1000?????? = 8000??????????????????????????¨?????§????????????

???????????¨????????????????????? t ?????????????????? R_t (t = 0, 1, 2 ,,, n-1)?????\?????¨??????????????????????????§??????????????? R_j - R_i (????????????j > i ??¨??????) ????????§???????±??????????????????????
??\???

?????????????????´??° n ?????????????????????????¶???? n ????????´??° R_t (t = 0, 1, 2 ,,, n-1) ?????????????????????????????????
??????

?????§??????????????????????????????????????????
??¶?´?

    2 \leq n \leq 200,000
    1 \leq R_t \leq 10^9

??\?????? 1

6
5
3
1
3
4
3

??\?????? 1 ??????????????????

3

??\?????? 2

3
4
3
2

??\?????? 2 ??????????????????

-1

=end

class Fx
  def initialize(v)
    @len = v.length
    @v = Array.new(@len, 0)
    (0..(@len-1)).each {|i|
      @v[i] = v[i]}
  end

  def srch1
    maxdif = -1000000000
    (0..(@len-1)).each {|i|
      ((i+1)..(@len-1)).each {|j|
        #puts "i=#{i} j=#{j} "
        if @v[j]-@v[i] > maxdif then
          maxdif = @v[j]-@v[i]
          #puts "maxdif=#{maxdif}"
        end
      }
    }
    maxdif
  end

  def srch2
    pmin = @v[0]
    pmax = @v[1..(@len-1)].max
    maxdif = pmax - pmin
    (2..(@len-1)).each{|k|
      if (pmin > @v[k-1]) then
        pmin = @v[k-1]
      end
      if (pmax == @v[k-1]) then
        pmax = @v[k..(@len-1)].max
      end

      if pmax - pmin > maxdif then
        maxdif = pmax - pmin
      end
    }
    maxdif
  end
end


class Main
  def initialize
#    fh = open("ALDS1_1_D_in.txt")
    fh = STDIN
    n = fh.gets.chomp.to_i
    count=0
    r = Array.new(n,0)
    (0..(n-1)).each {|i|
      r[i] = fh.gets.chomp.to_i
    }

    fx = Fx.new(r)
    #puts fx.srch1()
    puts fx.srch2()
  end
end

if $0==__FILE__ then
  Main.new()
end