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;
pair<long long int, long long int> exgcd(long long int a, long long int b) {
  if (b == 0) return pair<long long int, long long int>(1, 0);
  pair<long long int, long long int> p = exgcd(b, a % b);
  return pair<long long int, long long int>(p.second,
                                            p.first - p.second * (a / b));
}
long long int inverse(long long int a, long long int m) {
  pair<long long int, long long int> p = exgcd(a, m);
  while (p.first < 0) p.first += m;
  return p.first;
}
constexpr long long int pack[][4] = {
    {167772161, 243, 1 << 25, 3},          {469762049, 2187, 1 << 26, 3},
    {1107296257, 1087287097, 1 << 25, 10}, {1711276033, 969788637, 1 << 25, 29},
    {1811939329, 72705542, 1 << 26, 13},   {2013265921, 440564289, 1 << 27, 31},
    {2113929217, 1971140334, 1 << 25, 5}};
constexpr int usepacks[] = {1, 2};
template <long long int mod, long long int root, long long int root_pw>
void real_fft(vector<long long int>& v, bool invert) {
  int n = v.size();
  unsigned long long int a[n];
  for (int i = 0; i < n; i++) a[i] = v[i];
  for (int i = 1, j = 0; i < n; ++i) {
    int bit = n >> 1;
    for (; j >= bit; bit >>= 1) j -= bit;
    j += bit;
    if (i < j) swap(a[i], a[j]);
  }
  unsigned long long int ww[n];
  unsigned long long int wi = invert ? inverse(root, mod) : root;
  for (int i = n; i < root_pw; i *= 2) wi = wi * wi % mod;
  unsigned long long int t = 1;
  for (int i = 0; i < n; i++) {
    ww[i] = t;
    t = (t * wi) % mod;
  }
  unsigned long long int opt = ((unsigned long long int)(-1)) / mod / mod - 1;
  unsigned long long int tt = 0;
  for (int len = 2; len <= n; len *= 2) {
    unsigned long long int k = n / len;
    for (int i = 0; i < n; i += len) {
      unsigned long long int wn = 0;
      for (int j = 0; j < len / 2; j++) {
        unsigned long long int u = a[i + j],
                               v = a[i + j + len / 2] * ww[wn] % mod;
        a[i + j] = u + v;
        a[i + j + len / 2] = u + mod - v;
        wn = wn + k;
      }
    }
    tt++;
    if (tt == opt) {
      for (int i = 0; i < n; i++)
        while (a[i] > mod) a[i] -= mod;
      tt = 0;
    }
  }
  if (tt)
    for (int i = 0; i < n; i++)
      while (a[i] > mod) a[i] -= mod;
  if (invert) {
    unsigned long long int nrev = inverse(n, mod);
    for (int i = 0; i < n; i++) a[i] = a[i] * nrev % mod;
  }
  for (long long int i = 0; i < n; i++) v[i] = a[i];
}
template <long long int n>
void fft(vector<long long int>& a, bool invert) {
  real_fft<pack[usepacks[n]][0], pack[usepacks[n]][1], pack[usepacks[n]][2]>(
      a, invert);
}
vector<long long int> multiply(const vector<long long int>& a,
                               const vector<long long int>& b) {
  vector<long long int> fa(a.begin(), a.end()), fb(b.begin(), b.end()),
      fa2(a.begin(), a.end()), fb2(b.begin(), b.end());
  int n = 1;
  while (n < (int)(a.size() + b.size())) n <<= 1;
  fa.resize(n), fb.resize(n);
  fa2.resize(n), fb2.resize(n);
  int p1 = usepacks[0];
  int p2 = usepacks[1];
  long long int mod1 = pack[p1][0];
  long long int mod2 = pack[p2][0];
  fft<0>(fa, false), fft<0>(fb, false);
  for (int i = 0; i < n; ++i) fa[i] = (fa[i] * fb[i]) % mod1;
  fft<0>(fa, true);
  fft<1>(fa2, false), fft<1>(fb2, false);
  for (int i = 0; i < n; ++i) fa2[i] = (fa2[i] * fb2[i]) % mod2;
  fft<1>(fa2, true);
  long long int r12 = inverse(mod1, mod2);
  vector<long long int> res;
  res.resize(n);
  for (int i = 0; i < n; ++i) {
    int x1 = fa[i];
    int t = x1 % mod2;
    int x2 = ((fa2[i] + mod2 - t) * r12) % mod2;
    res[i] = x1 + x2 * mod1;
  }
  long long int carry = 0;
  for (int i = 0; i < n; ++i) {
    res[i] += carry;
    carry = res[i] / 1000;
    res[i] %= 1000;
  }
  while (res.size() > 1 && !res.back()) res.pop_back();
  return res;
}
void fast_3_pow(long long int k, vector<long long int>& ans) {
  ans = {1};
  if (k <= 0) return;
  vector<long long int> powans = {3};
  for (long long int t = k; t > 0; t /= 2) {
    vector<long long int> tmp;
    if (t % 2) {
      tmp = ans;
      ans = multiply(tmp, powans);
    }
    if (t > 1) {
      tmp = powans;
      powans = multiply(tmp, tmp);
    }
  }
}
bool first_is_BE(vector<long long int>& v1, vector<long long int>& v2) {
  if (v1.size() > v2.size()) return 1;
  if (v1.size() < v2.size()) return 0;
  for (long long int i = ((long long int)v1.size()) - 1; i >= 0; i--) {
    if (v1[i] > v2[i]) return 1;
    if (v1[i] < v2[i]) return 0;
  }
  return 1;
}
void small_mult(vector<long long int>& a, long long int b) {
  long long int carry = 0;
  for (int i = 0; i < (int)a.size() || carry; i++) {
    if (i == (int)a.size()) a.push_back(0);
    long long int cur = carry + a[i] * b;
    a[i] = cur % 1000;
    carry = cur / 1000;
  }
  while (a.size() > 1 && !a.back()) a.pop_back();
}
int main() {
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  int p = s.size();
  if (s == "1") {
    cout << "1";
    return 0;
  }
  if (s == "2") {
    cout << "2";
    return 0;
  }
  if (s == "3") {
    cout << "3";
    return 0;
  }
  if (s == "4") {
    cout << "4";
    return 0;
  }
  if (s == "5") {
    cout << "5";
    return 0;
  }
  if (s == "6") {
    cout << "5";
    return 0;
  }
  if (s == "7") {
    cout << "6";
    return 0;
  }
  if (s == "8") {
    cout << "6";
    return 0;
  }
  if (s == "9") {
    cout << "6";
    return 0;
  }
  vector<long long int> n;
  long long int tmp = 0;
  while (s.size() % 3 != 0) s = "0" + s;
  for (long long int i = 0; i < (long long int)s.size(); i++) {
    tmp *= 10;
    tmp += s[i] - '0';
    if ((i + 1) % 3 == 0) {
      n.push_back(tmp);
      tmp = 0;
    }
  }
  reverse(n.begin(), n.end());
  vector<long long int> v1, vt;
  long long int k;
  k = max((long long int)(p * logl(10) / logl(3) - 8), (long long int)0);
  fast_3_pow(k, v1);
  vt = v1;
  small_mult(v1, 4);
  while (1) {
    if (first_is_BE(v1, n)) {
      break;
    }
    k++;
    small_mult(v1, 3);
  }
  long long int ans3 = 3 * k + 4;
  k = max((long long int)(p * logl(10) / logl(3) - 8), (long long int)0);
  v1 = vt;
  while (1) {
    if (first_is_BE(v1, n)) {
      break;
    }
    k++;
    small_mult(v1, 3);
  }
  long long int ans1 = 3 * k;
  k = max((long long int)(p * logl(10) / logl(3) - 8), (long long int)0);
  v1 = vt;
  small_mult(v1, 2);
  while (1) {
    if (first_is_BE(v1, n)) {
      break;
    }
    k++;
    small_mult(v1, 3);
  }
  long long int ans2 = 3 * k + 2;
  cout << min(min(ans1, ans2), ans3);
  return 0;
}