#! /usr/bin/ruby -w
# encoding: utf-8

if $0 == __FILE__
  n = gets.to_i
  min = 200_000
  max = -200_000
  n.times do
    r = gets.to_i
    if r - min > max
      max = r - min
    end
    min = r < min ? r : min
  end
  puts max
end