n = gets.to_i _ = gets a = [] n.times do a << gets.to_i end p a.minmax.to_a.sum