n,m = gets.chomp.split.map(&:to_i)
jobs = Hash.new{|h,k| h[k] = Hash.new{|p,q| p[q]=0 }}
while str = gets
  a,b = str.chomp.split.map(&:to_i)
  next if a > m
  jobs[a][b] += 1
end
ret = 0
(1..m).each{|i|
  tmp = 0
  max = 0
  (1..i).each{|j|
    mm = jobs[i-j+1].keys.max || -1
    if mm > max
      max = mm
      tmp = i-j+1
    end
    }
  ret += max
  if jobs[tmp][max] == 1
    jobs[tmp].delete(max)
  else
    jobs[tmp][max] -= 1
  end
  }
p ret
h = {}
