def rank(score, pair, players) big = players.size - 1 count = 0 players.each_index do |small| break if small >= big if big == pair big -= 1 redo elsif small == pair next end 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 = (0 .. n - 2).bsearch do |i| rank(K + N[i], i, N) < M end if min_pair.nil? puts - 1 else puts N[min_pair] end