program main
implicit none
integer :: i, j, k, l, x, y, i1, i2, res
integer :: n, m
integer , allocatable :: a(:), b(:), c(:), bb(:), cc(:), d(:), dd(:)

read(*,*) n, m
allocate( a(n), b(n), c(n), bb(n), cc(n), d(n), dd(n) )
c = 0
do i = 1, n
   d(i) = i
   read(*,*) a(i), b(i)
end do
call quicksort2( n ,a, b, c, 1, n )
if( a(1) .gt. m ) then
   write(*,'(i0)') 0
   stop
end if
i2 = 1
res = 0
do i = m, 1, -1
   x = m+1-i
   i1 = i2
   do j = i1, n
      if( a(j) .le. x ) then
         i2 = j
      end if
      if( a(j) .gt. x ) exit
   end do
   y = 0
   call heapsort2( i2, b(1:i2), bb(1:i2), c(1:i2), cc(1:i2), d(1:i2), dd(1:i2) )
   do j = i2, 1, -1
      if( cc(j) == 0 ) then
         y = bb(j)
         c(dd(j)) = 1
         exit
      end if
   end do
   res = res + y
end do
write(*,'(i0)') res
!do i = 1, n
!   write(*,*) a(i), b(i), c(i)
!end do

stop
contains
recursive subroutine quicksort2(n, a, b, c, first, last)
  implicit none
  integer :: a(n), b(n), c(n)
  integer :: first, last
  integer ::  i, j, n
  integer ::  x, y, t, s, u
  
  x = a( (first+last) / 2 )
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i)
    a(i) = a(j)
    a(j) = t
    s = b(i)
    b(i) = b(j)
    b(j) = s
    u = c(i)
    c(i) = c(j)
    c(j) = u
    i=i+1
    j=j-1
  end do
  if (first < i - 1) call quicksort2(n, a, b, c, first, i - 1)
  if (j + 1 < last)  call quicksort2(n, a, b, c, j + 1, last)
end subroutine quicksort2
subroutine heapsort2(n, a, aa, b, bb, c, cc )
  implicit none
  integer,intent(in) :: n
  integer,intent(in) :: a(1:n), b(1:n), c(1:n)
  integer,intent(out) :: aa(1:n), bb(1:n), cc(1:n)
  
  integer ::i,k,j,l
  double precision :: t, u, v
  aa = a
  bb = b
  cc = c
  if(n.le.0)then
     write(6,*)"Error, at heapsort"; stop
  endif
  if(n.eq.1)return

  l=n/2+1
  k=n
  do while(k.ne.1)
     if(l.gt.1)then
        l=l-1
        t=aa(L)
        u=bb(L)
        v = cc(l)
     else
        t=aa(k)
        aa(k)=aa(1)
        u = bb(k)
        bb(k) = bb(1)
        v = cc(k)
        cc(k) = cc(1)
        k = k -1
        if(k.eq.1) then
           aa(1) = t
           bb(1) = u
           cc(1) = v
           exit
        endif
     endif
     i=l
     j=l+l
     do while(j.le.k)
        if(j.lt.k)then
           if(aa(j).lt.aa(j+1))j=j+1
        endif
        if (t.lt.aa(j))then
           aa(i)=aa(j)
           bb(i) = bb(j)
           cc(i) = cc(j)
           i=j
           j=j+j
        else
           j=k+1
        endif
     end do
     aa(i)=t
     bb(i) =u
     cc(i) = v
  end do

  return
end subroutine heapsort2
end program main