var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
})

rl.on('line', function (x) {
    lines.push(x);
});

rl.on("close", function () {
    var N = Number(lines[0]);
    var dp = Array(100000).fill(0);

    dp[Math.pow(9, 5)] = 1, dp[Math.pow(6, 5)] = 1;
    dp[Math.pow(9, 4)] = 1, dp[Math.pow(6, 4)] = 1;
    dp[Math.pow(9, 3)] = 1, dp[Math.pow(6, 3)] = 1;
    dp[Math.pow(9, 2)] = 1, dp[Math.pow(6, 2)] = 1;
    dp[Math.pow(9, 1)] = 1, dp[Math.pow(6, 1)] = 1;
    dp[1] = 1;

    for (var index = 1; index <= N; index++) {
        var a = Infinity; var b = Infinity; var c = Infinity; var d = Infinity;
        var e = Infinity; var f = Infinity; var g = Infinity; var h = Infinity;
        var i = Infinity; var j = Infinity; var k = Infinity;

        if (0 <= index - Math.pow(9, 5)) a = dp[index - Math.pow(9, 5)] + 1;
        if (0 <= index - Math.pow(6, 5)) b = dp[index - Math.pow(6, 5)] + 1;
        if (0 <= index - Math.pow(9, 4)) c = dp[index - Math.pow(9, 4)] + 1;
        if (0 <= index - Math.pow(6, 4)) d = dp[index - Math.pow(6, 4)] + 1;
        if (0 <= index - Math.pow(9, 3)) e = dp[index - Math.pow(9, 3)] + 1;
        if (0 <= index - Math.pow(6, 3)) f = dp[index - Math.pow(6, 3)] + 1;
        if (0 <= index - Math.pow(9, 2)) g = dp[index - Math.pow(9, 2)] + 1;
        if (0 <= index - Math.pow(6, 2)) h = dp[index - Math.pow(6, 2)] + 1;
        if (0 <= index - Math.pow(9, 1)) i = dp[index - Math.pow(9, 1)] + 1;
        if (0 <= index - Math.pow(6, 1)) j = dp[index - Math.pow(6, 1)] + 1;
        if (0 <= index - 1) k = dp[index - 1] + 1

        dp[index] = Math.min(a, b, c, d, e, f, g, h, i, j, k);
    }

    console.log(dp[N]);
});