var dp,dp2,rtodd,rt;


function bbb(n){

    var m = 0,a = 1,b = 1,c = 1;
    rtodd = [];
    rtodd.push(0);
    while(a <= n){
        if(a % 2){
            m++;
            rtodd.push(a);
        }
        c++;b+=c;a+=b;
    }

    dp2 = [];
    dp2[0] = [];
    dp2[0][0] = 0;
    for(var i = 1;i <= n;i++){
        dp2[0][i] = 1000000000;
    }
    for(var i = 1;i <= m;i++){
        dp2[i] = [];
        for(var j = 0;j <= n;j++){
            if(j < rtodd[i])
                dp2[i][j] = dp2[i - 1][j];
            else
                dp2[i][j] = dp2[i - 1][j] < dp2[i][j - rtodd[i]] + 1 ? dp2[i - 1][j] : dp2[i][j - rtodd[i]] + 1;
        }
    }

    return dp2[m][n];
}


function aaa(n){

    var m = 0,a = 1,b = 1,c = 1;
    rt = [];
    rt.push(0);
    while(a <= n){
        m++;
        rt.push(a);
        c++;b+=c;a+=b;
    }

    dp1 = [];
    dp1[0] = [];
    dp1[0][0] = 0;
    for(var i = 1;i <= n;i++){
        dp1[0][i] = 1000000000;
    }
    for(var i = 1;i <= m;i++){
        dp1[i] = [];
        for(var j = 0;j <= n;j++){
            if(j < rt[i])
                dp1[i][j] = dp1[i - 1][j];
            else
                dp1[i][j] = dp1[i - 1][j] < dp1[i][j - rt[i]] + 1 ? dp1[i - 1][j] : dp1[i][j - rt[i]] + 1;
        }
    }

    return dp1[m][n];
}

function Main(input){
    input = input.split("\n");
    
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));