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>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#pragma comment(linker, "/STACK:512000000")
using namespace std;
using li = long long;
using ld = long double;
void solve(bool);
void precalc();
clock_t start;
int main() {
  start = clock();
  int t = 1;
  cout.sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  precalc();
  while (t--) {
    solve(true);
  }
  cout.flush();
  return 0;
}
template <typename T>
T binpow(T q, T w, T mod) {
  if (!w) return 1 % mod;
  if (w & 1) return q * 1LL * binpow(q, w - 1, mod) % mod;
  return binpow(q * 1LL * q % mod, w / 2, mod);
}
template <typename T>
T gcd(T q, T w) {
  while (w) {
    q %= w;
    swap(q, w);
  }
  return q;
}
template <typename T>
T lcm(T q, T w) {
  return q / gcd(q, w) * w;
}
template <typename T>
void make_unique(vector<T>& vec) {
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
}
template <typename T>
void relax_min(T& cur, T val) {
  cur = min(cur, val);
}
template <typename T>
void relax_max(T& cur, T val) {
  cur = max(cur, val);
}
void precalc() {}
const int LBase = 4;
const int Base = 10000;
struct BigInt {
  vector<int> a;
  BigInt() {}
  BigInt(string s) {
    reverse(s.begin(), s.end());
    for (int i = 0; i < s.length(); i += LBase) {
      int en = min((int)s.length(), i + LBase);
      int cur = 0;
      for (int j = en - 1; j >= i; --j) {
        cur = cur * 10 + s[j] - '0';
      }
      a.push_back(cur);
    }
  }
  void norm() {
    int carry = 0;
    for (int i = 0; i < a.size() || carry > 0; ++i) {
      if (i == a.size()) {
        a.push_back(0);
      }
      a[i] += carry;
      carry = a[i] / Base;
      a[i] -= carry * Base;
    }
    while (a.size() > 0 && a.back() == 0) {
      a.pop_back();
    }
  }
  bool operator<(const BigInt& ot) const {
    if (a.size() != ot.a.size()) {
      return a.size() < ot.a.size();
    }
    for (int i = 0; i < a.size(); ++i) {
      int q = a[a.size() - 1 - i], w = ot.a[a.size() - 1 - i];
      if (q != w) {
        return q < w;
      }
    }
    return false;
  }
  BigInt operator*(int c) const {
    BigInt res = *this;
    for (int& x : res.a) {
      x *= c;
    }
    res.norm();
    return res;
  }
};
const int L = 20;
const int N = 1 << L;
bool fft_initialized = false;
using base = complex<double>;
using Poly = vector<double>;
const double pi = acosl(-1);
base angles[N * 2];
int bitrev[N];
const double eps = 1e-7;
inline bool eq(double x, double y) { return abs(x - y) < eps; }
void fft_init() {
  for (int n = 1; n <= N; n *= 2) {
    auto w = angles + n / 2;
    for (int i = 0; i < n / 2; ++i) {
      w[i] = polar(1.0, 2 * pi * i / n);
    }
  }
}
template <bool inverse>
void fft(base* y, base* x, int n, int k = 1) {
  if (n == 1) {
    *y = *x;
  } else {
    n /= 2;
    auto w = angles + n;
    fft<inverse>(y, x, n, k * 2);
    fft<inverse>(y + n, x + k, n, k * 2);
    for (int i = 0; i < n; ++i) {
      auto q = y[i + n] * (inverse ? conj(w[i]) : w[i]);
      y[i + n] = y[i] - q;
      y[i] = y[i] + q;
    }
  }
}
void fft(vector<base>& a, bool inverse = false) {
  int n = (int)a.size();
  static base b[1 << 21];
  for (int i = 0; i < n; ++i) {
    b[i] = a[i];
  }
  if (inverse) {
    fft<true>(a.data(), b, n);
    for (auto& x : a) {
      x /= n;
    }
  } else {
    fft<false>(a.data(), b, n);
  }
}
Poly multiply(Poly a, Poly b) {
  int n = 1;
  while (n < (int)a.size() || n < (int)b.size()) {
    n *= 2;
  }
  vector<base> ar(n + n), br(n + n);
  for (int i = 0; i < (int)a.size(); ++i) {
    ar[i] = a[i];
  }
  for (int i = 0; i < (int)b.size(); ++i) {
    br[i] = b[i];
  }
  fft(ar);
  fft(br);
  for (int i = 0; i < n + n; ++i) {
    ar[i] = ar[i] * br[i];
  }
  fft(ar, true);
  while (!ar.empty() && eq(norm(ar.back()), 0)) {
    ar.pop_back();
  }
  a.resize(ar.size());
  for (int i = 0; i < (int)a.size(); ++i) {
    a[i] = real(ar[i]);
  }
  return a;
}
BigInt multiply(const BigInt& a, const BigInt& b) {
  vector<double> A(a.a.begin(), a.a.end()), B(b.a.begin(), b.a.end());
  auto C = multiply(A, B);
  BigInt res;
  res.a.resize(C.size());
  li carry = 0;
  for (int i = 0; i < C.size() || carry; ++i) {
    if (i < C.size()) {
      carry += (li)round(C[i]);
    }
    if (i == res.a.size()) {
      res.a.push_back(0);
    }
    res.a[i] = carry % Base;
    carry /= Base;
  }
  res.norm();
  return res;
}
BigInt get_power(BigInt cur, int what) {
  if (what == 0) {
    return BigInt("1");
  }
  cur = get_power(cur, what / 2);
  cur = multiply(cur, cur);
  if (what & 1) {
    cur = cur * 3;
  }
  return cur;
}
void solve(bool read) {
  string s;
  if (read) {
    cin >> s;
  } else {
    s = string(1500000, '9');
    for (int i = 1; i < s.length(); ++i) {
      s[i] = (char)('0' + rand() % 10);
    }
  }
  if (s == "1") {
    cout << 1 << "\n";
    return;
  }
  BigInt num(s);
  double log_appr = ((int)s.length() - 1);
  log_appr = log_appr * log(10) / log(3);
  int b = max((int)(log_appr - 5), 0);
  if (b % 2 == 1) --b;
  fft_init();
  int need_b = b;
  BigInt three;
  three.a = vector<int>(1, 3);
  BigInt res = get_power(three, b);
  int ans = (int)1e9;
  auto relax = [&](int mult, int a) {
    auto cur_res = res * mult;
    int cur_ans = 3 * b + a * 2;
    while (cur_res < num) {
      cur_res = cur_res * 3;
      cur_ans += 3;
    }
    ans = min(ans, cur_ans);
  };
  relax(1, 0);
  relax(2, 1);
  relax(4, 2);
  cout << ans << "\n";
}