#!/usr/bin python3

# -*- coding: utf-8 -*-



import numpy as np



def main():

    N, W = list(map(int, input().split()))

    dp = [[0] * (W+1) for i in range(N+1)]

    dp = np.array(dp)

    #dp[i][j]  iまでをみてjの重さでの最大価値

    for i in range(1,N+1):

        w, v = list(map(int, input().split()))

        dp[i][:] = dp[i-1][:]

        dp[i][w:W+1] = np.maximum(dp[i-1][w:W+1], dp[i-1][:W+1-w] + v)



#    print(dp)

    print((dp[N][W]))



if __name__ == '__main__':

    main()
#!/usr/bin python3

# -*- coding: utf-8 -*-



import numpy as np



def main():

    N, W = list(map(int, input().split()))

    dp = [0] * (W+1)

    dp = np.array(dp)

    #dp[i][j]  iまでをみてjの重さでの最大価値

    for i in range(1,N+1):

        w, v = list(map(int, input().split()))

        dp[w:W+1] = np.maximum(dp[w:W+1], dp[:W+1-w] + v)



#    print(dp)

    print((dp[W]))



if __name__ == '__main__':

    main()
#!/usr/bin python3
# -*- coding: utf-8 -*-
import numpy as np


def main():
    N, W = list(map(int, input().split()))
    dp = [[0] * (W + 1) for i in range(N + 1)]
    dp = np.array(dp)
    # dp[i][j]  iまでをみてjの重さでの最大価値
    for i in range(1, N + 1):
        w, v = list(map(int, input().split()))
        dp[i][:] = dp[i - 1][:]
        dp[i][w : W + 1] = np.maximum(dp[i - 1][w : W + 1], dp[i - 1][: W + 1 - w] + v)
    #    print(dp)
    print((dp[N][W]))


if __name__ == "__main__":
    main()

#!/usr/bin python3
# -*- coding: utf-8 -*-
import numpy as np


def main():
    N, W = list(map(int, input().split()))
    dp = [0] * (W + 1)
    dp = np.array(dp)
    # dp[i][j]  iまでをみてjの重さでの最大価値
    for i in range(1, N + 1):
        w, v = list(map(int, input().split()))
        dp[w : W + 1] = np.maximum(dp[w : W + 1], dp[: W + 1 - w] + v)
    #    print(dp)
    print((dp[W]))


if __name__ == "__main__":
    main()

-    dp = [[0] * (W + 1) for i in range(N + 1)] +    dp = [0] * (W + 1) -        dp[i][:] = dp[i - 1][:] -        dp[i][w : W + 1] = np.maximum(dp[i - 1][w : W + 1], dp[i - 1][: W + 1 - w] + v) +        dp[w : W + 1] = np.maximum(dp[w : W + 1], dp[: W + 1 - w] + v) -    print((dp[N][W])) +    print((dp[W]))