#!/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
require "prime"
class Main
  def initialize
    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
    }

    maxdif = -1000000000
    (0..(n-1)).each {|i| 
      ((i+1)..(n-1)).each {|j| 
        #puts "i=#{i} j=#{j} "
        if r[j]-r[i] > maxdif then
          maxdif = r[j]-r[i] 
          #puts "maxdif=#{maxdif}"
        end
      }
    }
    puts maxdif
  end
end

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