N,M = map(int, input().split()) VM = [list(map(int, input().split())) for _ in range(N)] DP = [0]*(M+1) VM = sorted(VM, reverse=True, key=lambda x: x[0]) ans = 0 for v,m in VM: for i in reversed(range(M)): if DP[i]==0: continue if i+m<=M and DP[i+m]