raw_input = []
while (n = gets.to_i) != 0 do
  raw_input << n
end

input = raw_input[1..-1]
size = raw_input[0] - 1
max_v = input[1] - input[0]
min_v = input[0]

for j in 1..size do
  margin = input[j] - min_v
  max_v = (max_v > margin) ? max_v : margin
  min_v = (min_v < input[j]) ? min_v : input[j]
end
p max_v

