n,i=list(map(int,input().split())) sa=[list(map(int,input().split())) for _ in range (n)] dp=[[0]*(n+1) for _ in range(i+1)] for i,(s,a) in enumerate(sa): for j in range(n+1): if j>=s: dp[i+1][j]=max(dp[i][j],dp[i][j-s]+s+a) else: dp[i+1][j]=dp[i][j] print(dp[-1][-1])