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;
int work(int n) {
  int ans = 0;
  while (n > 4) n = (n + 2) / 3, ans += 3;
  return ans + n;
}
using ld = double;
struct cmp {
  ld x, y;
  cmp() : x(0), y(0) {}
  cmp(ld x_) : x(x_), y(0) {}
  cmp(ld x_, ld y_) : x(x_), y(y_) {}
  ld real() const { return x; }
  cmp operator+(const cmp &o) const { return cmp(x + o.x, y + o.y); }
  cmp operator-(const cmp &o) const { return cmp(x - o.x, y - o.y); }
  cmp operator*(const cmp &o) const {
    return cmp(x * o.x - y * o.y, x * o.y + y * o.x);
  }
  void operator*=(const cmp &o) { *this = *this * o; }
  void operator/=(ld k) { x /= k, y /= k; }
};
namespace FFT {
using T = cmp;
const ld PI = acosl(-1.0);
const int MAXB = 21;
const int MAXN = 1 << MAXB;
int rev[MAXN];
T roots[MAXN];
bool was_precalc{false};
void precalc() {
  if (was_precalc) {
    return;
  }
  was_precalc = 1;
  roots[0] = 1;
  int j = -1;
  for (int i = 1; i < MAXN; ++i) {
    if ((i & (i - 1)) == 0) {
      ld ang = 2 * PI / MAXN * i;
      roots[i] = T(cos(ang), sin(ang));
      ++j;
    } else {
      roots[i] = roots[1 << j] * roots[i ^ (1 << j)];
    }
  }
}
T get_root(int k, int n) { return roots[k * (MAXN / n)]; }
void fft(T *a, int K, bool inv) {
  precalc();
  const int n = 1 << K;
  rev[0] = 0;
  for (int i = 1; i < n; ++i) {
    rev[i] = (rev[i >> 1] >> 1) ^ ((i & 1) << (K - 1));
  }
  for (int i = 0; i < (int)(n); ++i) {
    if (i < rev[i]) {
      swap(a[i], a[rev[i]]);
    }
  }
  for (int len = 1; len < n; len *= 2) {
    vector<T> rs(len);
    for (int i = 0; i < (int)(len); ++i) {
      rs[i] = get_root(i, len * 2);
    }
    for (int i = 0; i < n; i += len * 2) {
      for (int j = 0; j < (int)(len); ++j) {
        const auto &w = rs[j];
        const auto x = a[i + j];
        const auto y = a[i + len + j];
        a[i + j] = x + w * y;
        a[i + len + j] = x - w * y;
        if (inv) {
          a[i + j] /= 2;
          a[i + len + j] /= 2;
        }
      }
    }
  }
  if (inv) {
    reverse(a + 1, a + n);
  }
}
vector<long long> mult(const vector<int> &a, const vector<int> &b) {
  int K = 0;
  while ((1 << K) < max((int)(a).size(), (int)(b).size())) {
    ++K;
  }
  ++K;
  vector<T> A(1 << K);
  vector<T> B(1 << K);
  for (int i = 0; i < (int)((int)(a).size()); ++i) {
    A[i] = a[i];
  }
  for (int i = 0; i < (int)((int)(b).size()); ++i) {
    B[i] = b[i];
  }
  fft(A.data(), K, false);
  fft(B.data(), K, false);
  for (int i = 0; i < (int)((int)(A).size()); ++i) {
    A[i] *= B[i];
  }
  fft(A.data(), K, true);
  vector<long long> res((int)(A).size());
  for (int i = 0; i < (int)((int)(A).size()); ++i) {
    res[i] = round(A[i].real());
  }
  while (!res.empty() && !res.back()) {
    res.pop_back();
  }
  return res;
}
vector<long long> square(const vector<int> &a) {
  int K = 0;
  while ((1 << K) < (int)(a).size()) {
    ++K;
  }
  ++K;
  vector<T> A(1 << K);
  for (int i = 0; i < (int)((int)(a).size()); ++i) {
    A[i] = a[i];
  }
  fft(A.data(), K, false);
  for (int i = 0; i < (int)((int)(A).size()); ++i) A[i] *= A[i];
  fft(A.data(), K, true);
  vector<long long> res((int)(A).size());
  for (int i = 0; i < (int)((int)(A).size()); ++i) {
    res[i] = round(A[i].real());
  }
  while (!res.empty() && !res.back()) {
    res.pop_back();
  }
  return res;
}
vector<long long> brut_mult(const vector<int> &a, const vector<int> &b) {
  vector<long long> c((int)(a).size() + (int)(b).size());
  for (int i = 0; i < (int)((int)(a).size()); ++i) {
    for (int j = 0; j < (int)((int)(b).size()); ++j) {
      c[i + j] += a[i] * b[j];
    }
  }
  return c;
}
};  // namespace FFT
const int base = int(1e3);
struct bignum {
  vector<int> v;
  bignum() {}
  bignum(int x) {
    assert(0 < x && x < base);
    v.push_back(x);
  }
  bignum(string s) {
    reverse((s).begin(), (s).end());
    for (int i = 0; i < (int)(s).size(); i += 3) {
      int dig = 0, coef = 1;
      for (int j = i; j < min(i + 3, (int)(s).size()); j++)
        dig += (s[j] - '0') * coef, coef *= 10;
      v.push_back(dig);
    }
  }
  bool operator<(const bignum &o) const {
    if ((int)(v).size() != (int)(o.v).size())
      return (int)(v).size() < (int)(o.v).size();
    for (int i = ((int)((int)(v).size()) - 1); i >= 0; --i)
      if (v[i] != o.v[i]) return v[i] < o.v[i];
    return false;
  }
  bignum mult(int c) const {
    bignum res;
    vector<int> &ans = res.v;
    ans.resize((int)(v).size());
    for (int i = 0; i < (int)((int)(v).size()); ++i) ans[i] = v[i] * c;
    for (int i = 0; i < (int)((int)(ans).size()); ++i)
      if (ans[i] >= base) {
        if (i + 1 == (int)(ans).size()) ans.push_back(0);
        ans[i + 1] += ans[i] / base;
        ans[i] %= base;
      }
    return res;
  }
  void square() {
    static vector<long long> ans;
    ans = FFT::square(v);
    for (int i = 0; i < (int)((int)(ans).size()); ++i)
      if (ans[i] >= base) {
        if (i + 1 == (int)(ans).size()) ans.push_back(0);
        ans[i + 1] += ans[i] / base;
        ans[i] %= base;
      }
    v.resize((int)(ans).size());
    copy((ans).begin(), (ans).end(), v.begin());
  }
  void print() {
    for (int i = ((int)((int)(v).size()) - 1); i >= 0; --i)
      ;
    ;
    ;
    ;
  }
};
bignum getpw(int m) {
  bignum res(1);
  string bitm;
  while (m) bitm += (m % 2 + '0'), m /= 2;
  reverse((bitm).begin(), (bitm).end());
  ;
  ;
  for (char ch : bitm) {
    res.square();
    if (ch == '1') res = res.mult(3);
  };
  ;
  return res;
}
const int bound = 36;
int solve(string ns) {
  if ((int)(ns).size() == 1) return work(ns[0] - '0');
  int m =
      int((log10l(ns[0] - '0') - log10l(4) + (int)(ns).size() - 1) / log10l(3));
  m = max(m, 0);
  bignum n(ns);
  bignum s = getpw(m);
  ;
  ;
  n.print();
  s.mult(bound).print();
  assert(s.mult(4) < n);
  assert(n < s.mult(bound));
  ;
  ;
  int left = 1, right = bound;
  while (right - left > 1) {
    const int mid = (left + right) / 2;
    if (s.mult(mid) < n)
      left = mid;
    else
      right = mid;
  }
  return 3 * m + work(right);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  string n;
  while (cin >> n) {
    auto ans = solve(n);
    cout << ans << endl;
  }
}