import sys

input = sys.stdin.readline



import numpy as np



def main():

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

  dp = np.zeros(W+1, dtype=np.int64)

  for _ in range(n):

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

    dp[w:W+1] = np.array((dp[:W-w+1]+v, dp[w:W+1])).max(axis=0)

  print((dp[W]))

  

if __name__ == "__main__":

  main()
import sys

input = sys.stdin.readline



import numpy as np



def main():

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

  dp = np.zeros(W+1, dtype=np.int64)

  for _ in range(n):

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

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

  print((dp[W]))

  

if __name__ == "__main__":

  main()
import sys

input = sys.stdin.readline
import numpy as np


def main():
    n, W = list(map(int, input().split()))
    dp = np.zeros(W + 1, dtype=np.int64)
    for _ in range(n):
        w, v = list(map(int, input().split()))
        dp[w : W + 1] = np.array((dp[: W - w + 1] + v, dp[w : W + 1])).max(axis=0)
    print((dp[W]))


if __name__ == "__main__":
    main()

import sys

input = sys.stdin.readline
import numpy as np


def main():
    n, W = list(map(int, input().split()))
    dp = np.zeros(W + 1, dtype=np.int64)
    for _ in range(n):
        w, v = list(map(int, input().split()))
        np.maximum(dp[: W - w + 1] + v, dp[w : W + 1], out=dp[w : W + 1])
    print((dp[W]))


if __name__ == "__main__":
    main()

-        dp[w : W + 1] = np.array((dp[: W - w + 1] + v, dp[w : W + 1])).max(axis=0) +        np.maximum(dp[: W - w + 1] + v, dp[w : W + 1], out=dp[w : W + 1])