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 double eps = 1e-2;
const int oo = 0x3f3f3f3f;
struct cmpl {
  long double real, imag;
  cmpl(long double a = 0, long double b = 0) : real(a), imag(b) {}
};
cmpl operator*(const cmpl &a, const cmpl &b) {
  return cmpl(a.real * b.real - a.imag * b.imag,
              a.real * b.imag + a.imag * b.real);
}
cmpl operator+(const cmpl &a, const cmpl &b) {
  return cmpl(a.real + b.real, a.imag + b.imag);
}
cmpl operator-(const cmpl &a, const cmpl &b) {
  return cmpl(a.real - b.real, a.imag - b.imag);
}
cmpl operator/(const cmpl &a, const long double &b) {
  return cmpl(a.real / b, a.imag / b);
}
const double PI = 2 * acos(0);
unordered_map<int, cmpl> wn_mem;
vector<cmpl> fft(vector<cmpl> v, int p) {
  vector<cmpl> res = v;
  for (int step = int((v).size()) / 2; step; step /= 2) {
    int n = int((v).size()) / step;
    cmpl wn = cmpl(cos(2 * p * PI / n), sin(2 * p * PI / n)), w(1, 0);
    if (wn_mem.find(n) == wn_mem.end()) {
      wn_mem[1] = cmpl(1, 0);
      wn_mem[2] = cmpl(-1, 0);
      wn_mem[4] = cmpl(0, 1);
      for (int k = 4; k < 6e6; k *= 2) {
        auto tmp = wn_mem[k];
        auto y =
            sqrt((1 - tmp.real) * (1 - tmp.real) + tmp.imag * tmp.imag) / 2;
        auto x = sqrt(1 - y * y);
        wn_mem[k * 2] = cmpl(x, y);
      }
    }
    assert(wn_mem.find(n) != wn_mem.end());
    wn = wn_mem[n];
    if (p == -1) wn.imag *= -1;
    for (int i = (0); i < (n / 2); i++) {
      for (int j = (0); j < (step); j++) {
        cmpl t = w * res[j + step * (2 * i + 1)];
        v[j + step * i] = res[j + step * 2 * i] + t;
        v[j + step * (i + n / 2)] = res[j + step * 2 * i] - t;
      }
      w = w * wn;
    }
    res = v;
  }
  if (p == -1)
    for (int i = (0); i < (int((res).size())); i++)
      res[i] = res[i] / int((res).size());
  return res;
}
vector<cmpl> poly_mult(vector<cmpl> p, vector<cmpl> q) {
  int N = 1;
  while (N < max(int((p).size()), int((q).size()))) N *= 2;
  p.resize(2 * N, 0);
  q.resize(2 * N, 0);
  p = fft(p, 1), q = fft(q, 1);
  vector<cmpl> pq(2 * N);
  for (int i = (0); i < (2 * N); i++) pq[i] = p[i] * q[i];
  return fft(pq, -1);
}
long long pow_mod(long long v, long long p, long long MOD) {
  if (p == 0) return 1;
  long long res = pow_mod((v * v) % MOD, p / 2, MOD);
  if (p & 1) res = (res * v) % MOD;
  return res;
}
long long inverse(long long v, long long prime) {
  return pow_mod(v, prime - 2, prime);
}
vector<long long> fft(vector<long long> v, int power, long long prime,
                      long long primitive_root) {
  vector<long long> res = v;
  if (power == -1) {
    primitive_root = inverse(primitive_root, prime);
  }
  for (int step = int((v).size()) / 2; step; step /= 2) {
    int n = int((v).size()) / step;
    long long wn = pow_mod(primitive_root, (prime - 1) / n, prime), w = 1;
    for (int i = (0); i < (n / 2); i++) {
      for (int j = (0); j < (step); j++) {
        long long t = (w * res[j + step * (2 * i + 1)]) % prime;
        auto tmp1 = res[j + step * 2 * i] + t;
        if (tmp1 >= prime) tmp1 -= prime;
        v[j + step * i] = tmp1;
        tmp1 = res[j + step * 2 * i] - t;
        if (tmp1 <= 0) tmp1 += prime;
        v[j + step * (i + n / 2)] = tmp1;
      }
      w = (w * wn) % prime;
    }
    res = v;
  }
  long long size_inverse = inverse(int((res).size()), prime);
  if (power == -1)
    for (int i = (0); i < (int((res).size())); i++)
      res[i] = (res[i] * size_inverse) % prime;
  for (int i = (0); i < (int((res).size())); i++)
    if (res[i] < 0) res[i] += prime;
  return res;
}
vector<long long> poly_mult(vector<long long> p, vector<long long> q,
                            long long prime, long long primitive_root) {
  int N = 1;
  while (N < max(int((p).size()), int((q).size()))) N *= 2;
  p.resize(2 * N, 0);
  q.resize(2 * N, 0);
  p = fft(p, 1, prime, primitive_root), q = fft(q, 1, prime, primitive_root);
  vector<long long> pq(2 * N);
  for (int i = (0); i < (2 * N); i++) pq[i] = (p[i] * q[i]) % prime;
  return fft(pq, -1, prime, primitive_root);
}
const int MAXN = 1.6e6;
char input[MAXN];
long double ldpow(long double v, int p) {
  if (p == 0) return 1;
  auto res = ldpow(v * v, p / 2);
  if (p & 1) return res * v;
  return res;
}
vector<cmpl> to_cmpl(const vector<long long> &a) {
  vector<cmpl> res(int((a).size()));
  for (int i = (0); i < (int((a).size())); i++) res[i] = cmpl(a[i]);
  return res;
}
vector<long long> to_ll(const vector<cmpl> &a) {
  vector<long long> res(int((a).size()));
  for (int i = (0); i < (int((a).size())); i++) {
    res[i] = (long long)a[i].real;
    if (abs(res[i] + 1 - a[i].real) < abs(res[i] - a[i].real)) res[i]++;
    if (abs(res[i] - 1 - a[i].real) < abs(res[i] - a[i].real)) res[i]--;
  }
  return res;
}
void normalize(vector<long long> &a, int f) {
  long long cur = 0;
  for (int i = (0); i < (int((a).size())); i++) {
    a[i] += cur;
    cur = a[i] / f;
    a[i] -= f * cur;
  }
  for (; cur; cur /= f) a.push_back(cur % f);
  while (a[int((a).size()) - 1] == 0) a.pop_back();
}
vector<long long> calc_3pn_ll(int p3) {
  vector<long long> base(1, 1);
  vector<long long> three(1, 3);
  while (p3) {
    int S = 1;
    while (S < max(int((base).size()), int((three).size()))) S *= 2;
    three.resize(2 * S);
    base.resize(2 * S);
    auto fft_t = fft((three), 1, 469762049, 3);
    if (p3 & 1) {
      auto fft_b = fft((base), 1, 469762049, 3);
      for (int i = (0); i < (2 * S); i++)
        fft_b[i] = (fft_b[i] * fft_t[i]) % 469762049;
      base = fft(fft_b, -1, 469762049, 3);
      normalize(base, 10);
    }
    p3 /= 2;
    if (p3 == 0) break;
    for (int i = (0); i < (2 * S); i++)
      fft_t[i] = (fft_t[i] * fft_t[i]) % 469762049;
    three = fft(fft_t, -1, 469762049, 3);
    normalize(three, 10);
  }
  return base;
}
vector<long long> calc_3pn(int p3) {
  vector<long long> base(1, 1);
  vector<long long> three(1, 3);
  while (p3) {
    int S = 1;
    while (S < max(int((base).size()), int((three).size()))) S *= 2;
    three.resize(2 * S);
    base.resize(2 * S);
    auto fft_t = fft(to_cmpl(three), 1);
    if (p3 & 1) {
      auto fft_b = fft(to_cmpl(base), 1);
      for (int i = (0); i < (2 * S); i++) fft_b[i] = (fft_b[i] * fft_t[i]);
      base = to_ll(fft(fft_b, -1));
      normalize(base, 10000);
    }
    p3 /= 2;
    if (p3 == 0) break;
    for (int i = (0); i < (2 * S); i++) fft_t[i] = (fft_t[i] * fft_t[i]);
    three = to_ll(fft(fft_t, -1));
    normalize(three, 10000);
  }
  vector<long long> nbase(int((base).size()) * 4);
  for (int i = (0); i < (int((base).size())); i++) {
    for (int j = (0); j < (4); j++) {
      nbase[i * 4 + j] = base[i] % 10;
      base[i] /= 10;
    }
  }
  base = nbase;
  while (base[int((base).size()) - 1] == 0) base.pop_back();
  return base;
}
int main() {
  if (0 == scanf("%s", input)) {
    fprintf(stderr, "Could not parse arguments\n");
  };
  int N = strlen(input);
  int p3 = max(0, (int)(N * log(10) / log(3)) - 6);
  auto p3res = calc_3pn(p3);
  if (N > 2)
    assert(int((p3res).size()) <= N - 2);
  else
    assert(int((p3res).size()) == 1 && p3res[0] == 1);
  assert(int((p3res).size()) > N - 6);
  while (true) {
    double vg = (input[0] - '0') / (double)p3res[int((p3res).size()) - 1];
    for (int i = (int((p3res).size())); i < (N); i++) vg *= 10;
    if (vg < 18) break;
    int cur = 0;
    for (int i = (0); i < (int((p3res).size())); i++) {
      p3res[i] = cur + p3res[i] * 3;
      cur = p3res[i] / 10;
      p3res[i] -= 10 * cur;
    }
    if (cur) p3res.push_back(cur);
    ++p3;
  }
  int res = oo;
  for (int p2 = (0); p2 < (3); p2++) {
    auto tmp = p3res;
    int f = 1 << p2;
    int cur = 0;
    for (int i = (0); i < (int((tmp).size())); i++) {
      tmp[i] = cur + tmp[i] * f;
      cur = tmp[i] / 10;
      tmp[i] -= 10 * cur;
    }
    if (cur) tmp.push_back(cur);
    int cres = p3 * 3 + p2 * 2;
    while (true) {
      if (int((tmp).size()) > N) break;
      if (int((tmp).size()) == N) {
        bool ok = true;
        for (int i = int(N) - 1; i >= (0); i--) {
          if (input[N - i - 1] - '0' < tmp[i]) break;
          if (input[N - i - 1] - '0' > tmp[i]) {
            ok = false;
            break;
          }
        }
        if (ok) break;
      }
      cres += 3;
      cur = 0;
      for (int i = (0); i < (int((tmp).size())); i++) {
        tmp[i] = cur + tmp[i] * 3;
        cur = tmp[i] / 10;
        tmp[i] -= 10 * cur;
      }
      if (cur) tmp.push_back(cur);
    }
    res = min(res, cres);
  }
  cout << max(1, res) << endl;
  return 0;
}