program name
    implicit none
    integer(8):: n,m
    integer(8),allocatable:: a(:), b(:)
    integer(8):: i, mon

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

    call double_merge_sort(a,b,1_8,n)

    mon=0
    do i=1,n
        mon=mon+a(i)*min(b(i),m)
        m=m-b(i)
        if (m <= 0) exit
    end do

    print*, mon
contains
subroutine swap(x,y)
    integer(8),intent(inout):: x,y
    integer(8):: t
    t=x;x=y;y=t
end subroutine


recursive subroutine double_merge_sort(a1,a2, fst, lst)
    integer(8),intent(inout):: a1(:), a2(:)
    integer(8),intent(in):: fst,lst
    integer(8):: mdl

    if (lst - fst < 2) then
        if (a1(fst) > a1(lst))then
            call swap(a1(fst), a1(lst))
            call swap(a2(fst), a2(lst))
        end if
        return
    end if

    mdl = (fst+lst)/2
    call double_merge_sort(a1,a2,fst,mdl)
    call double_merge_sort(a1,a2,mdl+1,lst)
    call double_merge(a1,a2,fst,mdl,lst)
end subroutine


subroutine double_merge(a1,a2,fst,mdl,lst)
    integer(8),intent(inout):: a1(:), a2(:)
    integer(8),intent(in):: fst,mdl,lst
    integer(8),allocatable:: t1(:),t2(:)
    integer(8):: li, ri, ti

    allocate(t1(lst-fst+1), t2(lst-fst+1))
    li = fst
    ri = mdl+1
    ti = 1

    do while (li <= mdl .and. ri <= lst)
        if (a1(li) <= a1(ri)) then
            t1(ti) = a1(li)
            t2(ti) = a2(li)
            li=li+1
        else
            t1(ti) = a1(ri)
            t2(ti) = a2(ri)
            ri=ri+1
        end if
        ti=ti+1
    end do

    if (li <= mdl) then
        t1(ti:) = a1(li:mdl)
        t2(ti:) = a2(li:mdl)
    else
        t1(ti:) = a1(ri:lst)
        t2(ti:) = a2(ri:lst)
    end if

    a1(fst:lst) = t1(:)
    a2(fst:lst) = t2(:)
    deallocate(t1)
    deallocate(t2)
end subroutine
end program name