#!/usr/bin/env ruby

size = nil
input = []
while line = gets
  if size == nil
    size = line
  else
    input << line.chomp!.to_i
  end
end
maxv = -1000000000000000000
minv = input[0]
1.upto(input.size-1) do |j|
  maxv = input[j] - minv if maxv < input[j]-minv
  minv = input[j]  if minv > input[j]

end

p maxv