N,ww = map(int, input().split()) dp = [ [-float("inf")] * (ww+1) for _ in range(N+1) ] for i in range(ww+1): dp[0][i] = 0 V = list() W = list() for _ in range(N): v,w = map(int, input().split()) V.append(v) W.append(w) for i in range(N): for j in range(ww+1): if 0<=j-W[i]<=ww: dp[i+1][j] = max(dp[i][j-W[i]]+V[i],dp[i][j]) else: dp[i+1][j] = max(dp[i+1][j],dp[i][j]) print(max(dp[N]) if max(dp[N])>0 else -1)