n = gets.to_i
rt = [gets.to_i]
got2 = gets.to_i
for i in 2..n-2
  got1 = gets.to_i
  if rt[-1]<got2
    if got2<=got1
      got2 = got1
    else
      rt<<got2
    end
  end
  if rt[-1]>got2
    if got2>=got1
      got2 = got1
    else
      rt<<got2
    end
  end
end
rt << gets.to_i 
l = rt.size
ans = rt[1]-rt[0]
for i in 0..l-1
  for j in i+1..l-1
    x = rt[j]-rt[i]
    ans = x if ans<x
  end
end
puts ans