#include <iostream>
using namespace std;
int main() {
long long n;
int k = 0;
cin >> n;
while (n > 0) {
k += n%3 + 1;
n /= 3;
}
cout << k - 2;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7Cglsb25nIGxvbmcgbjsKCWludCBrID0gMDsKCWNpbiA+PiBuOwoJd2hpbGUgKG4gPiAwKSB7CgkJayArPSBuJTMgKyAxOwoJCW4gLz0gMzsKCX0gCgljb3V0IDw8IGsgLSAyOwoJcmV0dXJuIDA7Cn0=