
n = gets.to_i

a = gets.to_i
b = gets.to_i

can = b-a

if n==2 then
puts can

else

if a>b then
left = b
end

m = n-2


m.times{
right = gets.to_i
d = right - left
if d>can then
can = d
end
if right < left then
left = right
end
}

puts can

end
