N,I = map(int,input().split()) A = [0]+[list(map(int,input().split())) for _ in range(N)] dp = [[0 for _ in range(I+1)] for _ in range(N+1)] for j in range(I+1): if j>=A[1][0]: dp[1][j] = A[1][1] for i in range(2,N+1): for j in range(I+1): dp[i][j] = dp[i-1][j] if j>=A[i][0]: dp[i][j] = max(dp[i][j],dp[i-1][j-A[i][0]]+A[i][1]) print(dp[N][I])