n, m = gets.split.map(&:to_i)
abs = []
n.times{ abs << gets.split.map(&:to_i) }

dp = Array.new(m+1, Array.new(2))
dp[0][0] = 0
dp[0][1] = []
# m日後、最適なタスクindex

abs.sort! do |a, b|
  if a[0] > b[0]
    1
  elsif a[0] == b[0]
    a[1] < b[1] ? 1 : -1
  else
    -1
  end
end

(1..m).each do |d|
  d
  candidate = nil
  abs.each_with_index{|ab, idx|
    if ab[0] <= d && !dp[d-1][1].include?(idx)
      if candidate.nil? || ab[1] > abs[candidate][1]
        candidate = idx
      end
    end
  }
  if candidate
    dp[d][1] = dp[d-1][1]
    dp[d][1] << candidate
    dp[d][1].flatten!
    dp[d][0] = dp[d-1][0] + abs[candidate][1]
  else
    dp[d][1] = dp[d-1][1]
    dp[d][0] = dp[d-1][0]
  end
end

p dp.last[0]