program Knapsack_2
    implicit none
    integer(4):: n,wn
    integer(8), parameter:: inf=400000000000_8
    integer(8),allocatable:: w(:), v(:)
    integer(8):: dp(0:100000), ndp(0:100000), ans
    integer(4):: i,j

    read*, n,wn
    allocate(w(n), v(n))
    do i=1,n
        read*, w(i), v(i)
    end do

    dp(:) = inf
    ndp(:) = inf

    dp(0) = 0
    ndp(0) = 0

    do i=1, n
        do j=1, 100000
            if (j < v(i)) then
                ndp(j) = dp(j)
            else
                ndp(j) = min(dp(j), dp(j-v(i))+w(i))
            end if
        end do
        dp(:) = ndp(:)
    end do

    ans = 0
    do i=1, 100000
        if (dp(i) <= wn) then
            ans = max(ans,i)
        end if
    end do
    print*, ans
end program Knapsack_2