def find_the_remainder(p)
  length = p.length
  output = []
  minv = 20000000000001
  for i in 0..(length-2)
      if minv > p[1]
        minv = p[i]
      else
      result = (p[i]) - (minv)
        output.push(result)
      end
    end
  end
  return output
end

# def find_the_remainder(p)
#   length = p.length
#   maxv = 20000000000001
#   minv = -2000000000001
#   for i in 0..(length-1)
#     if maxv <
# end
n = gets.chomp.to_i
input_values = []
n.times do
  input_value = gets.chomp.to_i
  input_values.push(input_value)
end

puts find_the_remainder(input_values).max