import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int n) {
    auto dp = new int[n + 1];
    for (int i = 1; i <= n; i++)
        dp[i] = i;

    foreach (coin; [6, 9]) {
        int c = 1;
        while (true) {
            c *= coin;
            if (c > n) break;

            for (int i = c; i <= n; i++) {
                dp[i] = min(dp[i], dp[i - c] + 1);
            }
        }
    }
    return dp[n];
}

void main() {
    int n = readint;

    int ans = calc(n);
    writeln(ans);
}
