program kadai
    implicit none
integer  ::  n,m
integer,allocatable  ::  a(:),b(:)
integer  ::  i,j,today,money,check

    read(*,*) n,m
    allocate(a(n))
    allocate(b(n))

    do i=1,n
        read(*,*) a(i),b(i)
    end do

    money=0
    do i=1,m
        today=0
        do j=1,n
            if (a(j)<i+1) then
                if (b(j)>today) then
                    today=b(j)
                    check=j
                end if
            end if
        end do
        if (check>0) then
            b(check)=0
        end if
        money=money+today
    end do

    write(*,*) money
stop
contains

end program kadai
