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 0..size do
  for i in 0..j-1 do
    margin = input[j] - min_v
    max_v = (max_v > margin) ? max_v : margin
    min_v = (min_v < input[i]) ? min_v : input[i]
  end
end
p max_v


