Problem: You are working as an analyst in a company working on a new system for big data storage. This system will store n different objects. Each object should have a unique ID.

To create the system, you choose the parameters of the system — integers m ≥ 1 and b_{1}, b_{2}, …, b_{m}. With these parameters an ID of some object in the system is an array of integers [a_{1}, a_{2}, …, a_{m}] where 1 ≤ a_{i} ≤ b_{i} holds for every 1 ≤ i ≤ m.

Developers say that production costs are proportional to ∑_{i=1}^{m} b_{i}. You are asked to choose parameters m and b_{i} so that the system will be able to assign unique IDs to n different objects and production costs are minimized. Note that you don't have to use all available IDs.

Input

In the only line of input there is one positive integer n. The length of the decimal representation of n is no greater than 1.5 ⋅ 10^{6}. The integer does not contain leading zeros.

Output

Print one number — minimal value of ∑_{i=1}^{m} b_{i}.

Examples

Input

36


Output

10


Input

37


Output

11


Input

12345678901234567890123456789


Output

177

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int64_t logn = 22;
const int64_t maxn = 1 << logn;
const double pi = acos(-1);
complex<double> w[maxn];
template <typename T>
void fft(T *in, T *out, int64_t n, int64_t k) {
  if (n == 1) {
    *out = *in;
    return;
  }
  n /= 2;
  fft(in, out, n, 2 * k);
  fft(in + k, out + n, n, 2 * k);
  for (int64_t i = 0; i < n; i++) {
    complex<double> t = w[i + n] * out[i + n];
    out[i + n] = out[i] - t;
    out[i] = out[i] + t;
  }
}
const int64_t mod = 1e4, len = 4;
void normalize(vector<int64_t> &ans) {
  int64_t carry = 0;
  for (int64_t i = 0; i < (int64_t)ans.size(); i++) {
    ans[i] += carry;
    carry = ans[i] / mod;
    ans[i] -= carry * mod;
  }
  if (carry) {
    ans.push_back(carry);
  }
  while (ans.back() == 0 && ans.size() > 1) {
    ans.pop_back();
  }
}
complex<double> sqr(complex<double> x) { return x * x; }
vector<int64_t> mul(vector<int64_t> a, vector<int64_t> b) {
  int64_t n = a.size() + b.size();
  while (__builtin_popcount(n) != 1) n++;
  while ((int64_t)a.size() < n) a.push_back(0);
  while ((int64_t)b.size() < n) b.push_back(0);
  vector<complex<double> > A(n);
  for (int64_t i = 0; i < n; i++) {
    A[i] = complex<double>(a[i], b[i]);
  }
  vector<complex<double> > nA(n);
  fft(A.data(), nA.data(), n, 1);
  for (int64_t i = 0; i < n; i++) {
    A[i] = (sqr(nA[i]) - sqr(conj(nA[(n - i) % n]))) / complex<double>(0, 4);
  }
  fft(A.data(), nA.data(), n, 1);
  reverse(begin(nA) + 1, end(nA));
  vector<int64_t> ans(n);
  for (int64_t i = 0; i < n; i++) {
    ans[i] = llround(real(nA[i]) / n);
  }
  normalize(ans);
  return ans;
}
vector<int64_t> ppow(vector<int64_t> x, int64_t n) {
  if (n == 0) {
    return {1};
  } else if (n == 1 && false) {
    return x;
  } else {
    auto t = ppow(x, n / 2);
    t = mul(t, t);
    return n % 2 ? mul(t, x) : t;
  }
}
const int64_t loggn = 22;
vector<int64_t> pows[loggn];
string to_string(vector<int64_t> x) {
  stringstream ss;
  reverse(begin(x), end(x));
  ss << x[0];
  for (int64_t i = 1; i < (int64_t)x.size(); i++) {
    ss << setfill('0') << setw(len) << x[i];
  }
  return ss.str();
}
void print(vector<int64_t> x) { cout << to_string(x) << endl; }
bool les(const string &a, const string &b) {
  if (a.size() != b.size()) {
    return a.size() < b.size();
  } else {
    return a < b;
  }
}
vector<int64_t> mul(vector<int64_t> a, int64_t c) {
  for (auto &it : a) {
    it *= c;
  }
  normalize(a);
  return a;
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  for (int64_t z = 1; z < maxn; z *= 2) {
    for (int64_t i = 0; i < z; i++) {
      w[z + i] = polar(1., pi * i / z);
      assert(z + i < maxn);
    }
  }
  pows[0] = {3};
  for (int64_t i = 1; i < loggn; i++) {
    pows[i] = mul(pows[i - 1], pows[i - 1]);
  }
  string control;
  cin >> control;
  if (control == "1") {
    cout << 1 << endl;
    return 0;
  } else if (control == "2") {
    cout << 2 << endl;
    return 0;
  }
  int64_t ans = 1e9;
  int64_t k =
      max<int64_t>(0, (int64_t)round(control.size() * log(10) / log(3)) - 3);
  vector<int64_t> cur = ppow({3}, k);
  while (!les(control, to_string(mul(cur, 9)))) {
    cur = mul(cur, 3);
    k++;
  }
  if (!les(to_string(mul(cur, 3)), control)) {
    ans = min(ans, 3 * k + 3);
  }
  if (!les(to_string(mul(cur, 2 * 2)), control)) {
    ans = min(ans, 3 * k + 2 + 2);
  }
  if (!les(to_string(mul(cur, 3 * 2)), control)) {
    ans = min(ans, 3 * k + 3 + 2);
  }
  if (!les(to_string(mul(cur, 3 * 3)), control)) {
    ans = min(ans, 3 * k + 3 + 3);
  }
  cout << ans << endl;
  return 0;
}