N, K = gets.split.map(&:to_i) Q = N.times.map { gets.split.map(&:to_i) } def f(x) rank = 0 Q.each do |a, b| next if x < a if b < x rank += (b - a + 1) else rank += (x - a + 1) end end K <= rank end ok = 10 ** 9 ng = 0 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if f(x) ok = x else ng = x end end puts ok