program answer
  implicit none
  integer(16) :: i, N, M, sum, count, last, aa
  integer(16), allocatable :: A(:), B(:)
  read(*,*) N, M
  allocate(A(N),B(N))
  do i = 1, N
     read(*,*) A(i), B(i)
  end do

  sum=0
  count=0
  do
     if(count>=M) then
        exit
     end if
     aa=dot_product(B(minloc(A)),B(minloc(A)))
     aa=int(sqrt(dble(aa)))
     sum=sum+minval(A)*aa
     count=count+aa
     last=minval(A)
     A(minloc(A))=1000000001
  end do

  if(count>M) then
     sum=sum-(count-M)*last
  end if

  write(*,*) sum
  deallocate(A,B)
  stop
 end program answer
     