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

if $0 == __FILE__
  max = 1 - 10**9
  n   = gets.to_i
  min = gets.to_i
  (n - 1).times do
    r = gets.to_i
    if r - min > max
      max = r - min
    end
    min = r < min ? r : min
  end
  puts max
end