#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

def max_profit(rs, n)
  r0 = rs.shift
  r1 = rs.shift
  min_r = [r0, r1].min
  max_p = r1 - r0
  rs.each do |r|
    cur_p = r - min_r
    max_p = [max_p, cur_p].max
    min_r = [min_r, r].min
  end
  max_p
end

if __FILE__ == $0
  n, *rs = ARGF.readlines.map { |r| r.to_i }
  # assert(n == rs.size)
  # assert(n >= 2)
  max_p = max_profit(rs, n)
  puts max_p
end

# end