Public Class Program
  Shared Sub Main()
    Dim nm As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
    Dim n As Long = nm(0)
    Dim m As Long = nm(1)
    Dim arrayA(0 To n - 1) As Long
    Dim arrayB(0 To n - 1) As Long
    Dim usedIndex(0 To n - 1) As Integer
    For i As Long = 0 To n - 1
      Dim ab As Long() = Array.ConvertAll(Of String, Long)(Console.ReadLine().Split(" "), AddressOf Long.Parse)
      arrayA(i) = ab(0)
      arrayB(i) = ab(1)
      usedIndex(i) = 0
    Next
    Dim ans As Long = 0
    For i As Long = 1 To m
      Dim maxReward As Long = 0
      Dim maxRewardIndex As Long = -1
      For j As Long = 0 To n - 1
        If arrayA(j) <= i AndAlso usedIndex(j) = 0 AndAlso maxReward < arrayB(j) Then
          maxReward = arrayB(j)
          maxRewardIndex = j
        End If
      Next
      If maxRewardIndex <> -1 Then
        ans += maxReward
        usedIndex(maxRewardIndex) = 1
      End If
    Next
    Console.WriteLine(ans.ToString())
  End Sub
End Class