#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
const int mod = 1e9 + 9;
int main() {
  ll n, k;
  cin >> n >> k;
  ll p = 1;
  ll ans = 0;
  while (p <= n && n % p == 0) {
    p *= 3;
    ans++;
  }
  cout << (n / p) + 1 << endl;
}
