import sys # import pypyjit import itertools import heapq import math import bisect from collections import deque, defaultdict from functools import lru_cache, cmp_to_key # for AtCoder Easy test if __file__ == 'prog.py': pass else: sys.setrecursionlimit(10 ** 6) # pypyjit.set_param('max_unroll_recursion=-1') input = sys.stdin.readline def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input()[:-1] N, I = readints() R = [tuple(readints()) for _ in range(N)] dp = [0] * (I + 1) for i in range(N): s, a = R[i] for j in range(I, 0, -1): if j - s < 0: break dp[j] = max(dp[j], dp[j - s] + a) print(max(dp))