#include <iostream>
#define NUM 3
#define POW 729
using namespace std;
int nearest(int weight) {
for (int i = 1; i < POW; i*=NUM){
if (abs(i - weight) < abs(i*NUM - weight)) {
return i;
}
}
}
int main() {
int right_bowl, left_bowl = 0, count = 0;
cin >> right_bowl;
while (right_bowl != left_bowl) {
if (right_bowl > left_bowl) {
left_bowl += nearest(abs(right_bowl - left_bowl));
}
else right_bowl += nearest(abs(right_bowl - left_bowl));
count++;
}
cout << count;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojZGVmaW5lIE5VTSAzCiNkZWZpbmUgUE9XIDcyOQp1c2luZyBuYW1lc3BhY2Ugc3RkOwogCmludCBuZWFyZXN0KGludCB3ZWlnaHQpIHsKICAgIGZvciAoaW50IGkgPSAxOyBpIDwgUE9XOyBpKj1OVU0pewogICAgICAgIGlmIChhYnMoaSAtIHdlaWdodCkgPCBhYnMoaSpOVU0gLSB3ZWlnaHQpKSB7CiAgICAgICAgICAgIHJldHVybiBpOwogICAgICAgIH0KICAgIH0KfQogCmludCBtYWluKCkgewogIGludCByaWdodF9ib3dsLCBsZWZ0X2Jvd2wgPSAwLCBjb3VudCA9IDA7CiAgY2luID4+IHJpZ2h0X2Jvd2w7CiAgd2hpbGUgKHJpZ2h0X2Jvd2wgIT0gbGVmdF9ib3dsKSB7CiAgICBpZiAocmlnaHRfYm93bCA+IGxlZnRfYm93bCkgewogICAgICAgICAgICBsZWZ0X2Jvd2wgKz0gbmVhcmVzdChhYnMocmlnaHRfYm93bCAtIGxlZnRfYm93bCkpOwogICAgICAgIH0KICAgIGVsc2UgcmlnaHRfYm93bCArPSBuZWFyZXN0KGFicyhyaWdodF9ib3dsIC0gbGVmdF9ib3dsKSk7CiAgICBjb3VudCsrOwogIH0KICBjb3V0IDw8IGNvdW50Owp9