#include <bits/stdc++.h>
using namespace std;
long long int coins[50];
int arr[100010];
bool chk;
void precal() {
  coins[1] = 1;
  for (int i = 2; i <= 40; i++) {
    coins[i] = coins[i - 1] * 3;
  }
}
int main() {
  precal();
  long long int n, x, cnt, pos;
  cin >> x;
  cnt = 0;
  for (int i = 39; i >= 1; i--) {
    if (x % coins[i] == 0) {
      cnt = (x / coins[i + 1]) + 1;
      break;
    }
  }
  cout << cnt << endl;
  return 0;
}
