no = gets.to_i
arr = Array.new(no){
    gets.to_i
}
min = arr[0]
max = -200000
(no-1).times { |i|
    if max < arr[i+1]-min
        max = arr[i+1]-min
    end

    if arr[i+1] < min
        min = arr[i+1]
    end
}
puts max