process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });
    
    main();    
});

function readline() {
    return inputString[currentLine++];
}

function ti(a){
    for(let i = 0; i < a.length; i++)
        a[i] = parseInt(a[i]);

    return a;
}

function main(){
    let [n,k] = ti(readline().split(' '));
    let w = new Array(n);
    let v = new Array(n);

    for(let i = 0; i < n; i++){
        let [x,y] = ti(readline().split(' '));
        w[i] = x;
        v[i] = y;
    }

    let dp = new Array(k+1);
    for(let i = 0; i < k+1; i++){
        dp[i] = new Array(n);
    }

    for(let i = 0; i < k+1; i++){
        for(let j = 0; j < n; j++){
            if(j === 0){
                dp[i][j] = w[j] <= i ? v[j] : 0;
            }else{
                if(i-w[j] >= 1)
                    dp[i][j] = Math.max(dp[i][j-1], v[j] + dp[i-w[j]][j-1]);
                else
                    dp[i][j] = dp[i][j-1];
            }            
        }
    }

    console.log(dp[k][n-1]);
}