def prize(score, pair, players) big = players.size - 1 count = 0 players.each_index do |small| break if small >= big next if big == pair || small == pair oscore = players[big] + players[small] if oscore > score count += 1 big -= 1 end end count end n, M = gets.split.map(&:to_i) N = n.times.map{ gets.to_i } K = N.shift N.sort! min_pair = N.bsearch_index do |pair| if pair >= N.size false else prize(N[pair] + K, pair, N) > M end end if min_pair.nil? puts -1 else puts N[min_pair] end