#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;
}