#include <bits/stdc++.h>
using namespace std;
long long INF = 1LL<<60;
using ll = long long;
using vll = vector<ll>;
using mll = map<ll, ll>;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

//* calculate x^n mod something in O(log n) -- recursive version
ll my_pow(ll x, ll n){
    if(n == 0) return 1;
    ll res = my_pow(x*x , n/2);
    if(n & 1) res = res * x ;
    return res;
}

void solve(long long N){
    rep(A, 1, 38){
        rep(B, 1, 26){
            ll tmp = my_pow(3, A) + my_pow(5, B);
            if(tmp == N){
                cout << A << " " << B << endl;
                return;
            }
        }
    }
    cout << -1 << endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    solve(N);
    return 0;
}

#include <iostream>
#include <cmath>
#include <stdio.h>
#include <string.h>
#include <bits/stdc++.h>
#include <vector>
#include <array> 
#include <tuple>
using namespace std; 

int main(){
  long long N;
  cin >> N;
  long long p, S;
  S=N;
  p=1;
  for (int i=0; i<=60; i++){
    S=min(N/p+i+N%p, S);
    p=2*p;
  }
  cout << S << endl;
}