n, x = read_line.split.map &.to_i ab = (1..2).map { read_line.split.map &.to_i }.transpose.map { |(a, b)| {a - x, b} } goal = -ab.sum(&.[0]) if goal <= 0 puts 0 elsif ab.none? { |a, b| a >= 0 } puts -1 else dp = [0] + [10**9] * (500 * 100) ab.select { |a, b| a < 0 }.each { |a, b| (0...dp.size + a).reverse_each { |i| dp[i - a] = {dp[i - a], dp[i] + b}.min } } puts dp[goal..].min end