N, I = map(int, input().split()) ramens = [tuple(map(int, input().split())) for _ in range(N)] dp = [[0]*(I+1) for _ in range(N+1)] for n in range(N): sio, aji = ramens[n] for i in range(I+1): dp[n+1][i] = max(dp[n+1][i], dp[n][i]) if I < i + sio: continue dp[n+1][i+sio] = max(dp[n+1][i+sio], dp[n][i]+aji) print(max(dp[N]))