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;
inline int gi() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 3) + (x << 1) + ch - 48;
    ch = getchar();
  }
  return x * f;
}
template <typename T>
inline void Max(T &a, T b) {
  if (a < b) a = b;
}
template <typename T>
inline void Min(T &a, T b) {
  if (a > b) a = b;
}
const int N = 500007, Ba = 10000;
const long long inf = 1e18;
const long double pi = acos(-1.0), eps = 0.5, eps2 = 1e-8;
int len, n;
long long ans = inf, now;
char s[N << 2];
struct cpx {
  long double r, i;
  cpx() {}
  cpx(long double r, long double i) : r(r), i(i) {}
  cpx operator*(const cpx &x) {
    return cpx(r * x.r - i * x.i, r * x.i + i * x.r);
  }
  cpx operator*=(const cpx &x) { return *this = *this * x; }
  cpx operator+(const cpx &x) { return cpx(r + x.r, i + x.i); }
  cpx operator-(const cpx &x) { return cpx(r - x.r, i - x.i); }
} a[N << 2], b[N << 2];
struct Big {
  vector<cpx> v;
  Big() {}
  Big(int x) {
    v.resize(1);
    v[0] = cpx(x, 0);
  }
  void init(int x) {
    v.resize(1);
    v[0] = cpx(x, 0);
  }
  bool operator<=(const Big &rhs) const {
    if (v.size() != rhs.v.size()) return v.size() < rhs.v.size();
    for (int i = v.size() - 1; ~i; --i) {
      if (v[i].r < rhs.v[i].r) return 1;
      if (v[i].r > rhs.v[i].r) return 0;
    }
    return 1;
  }
} A, B, C, tmp;
void fft(cpx *c, int n, int f) {
  for (int i = 0, j = 0; i < n; ++i) {
    if (i > j) swap(c[i], c[j]);
    for (int k = n >> 1; (j ^= k) < k; k >>= 1)
      ;
  }
  for (int i = 1; i < n; i <<= 1) {
    cpx wn(cos(pi / i), f * sin(pi / i));
    for (int j = 0; j < n; j += i << 1) {
      cpx w(1, 0);
      for (int k = 0; k < i; ++k, w *= wn) {
        cpx x = c[j + k], y = w * c[j + k + i];
        c[j + k] = x + y;
        c[j + k + i] = x - y;
      }
    }
  }
  if (f == -1)
    for (int i = 0; i < n; ++i) c[i].r /= n;
}
Big operator*(Big A, Big B) {
  Big res = A;
  int la = res.v.size(), lb = B.v.size();
  for (len = 1; len <= la + lb - 2; len <<= 1)
    ;
  fill(a, a + len, cpx(0, 0));
  fill(b, b + len, cpx(0, 0));
  for (int i = 0; i < res.v.size(); ++i) a[i] = res.v[i];
  for (int i = 0; i < B.v.size(); ++i) b[i] = B.v[i];
  fft(a, len, 1);
  fft(b, len, 1);
  for (int i = 0; i < len; ++i) a[i] *= b[i];
  fft(a, len, -1);
  res.v.resize(la + lb - 1);
  B.v.resize(lb);
  for (int i = 0; i < res.v.size(); ++i) res.v[i] = a[i];
  for (int i = 0; i < res.v.size() - 1; ++i) {
    long long t = (long long)(res.v[i].r / Ba + eps2);
    res.v[i + 1].r += t;
    res.v[i].r -= t * Ba;
  }
  while (res.v[res.v.size() - 1].r >= Ba) {
    if (res.v[res.v.size() - 1].r >= Ba) {
      long long t = (long long)(res.v[res.v.size() - 1].r / Ba + eps2);
      res.v.push_back(cpx(t, 0));
      res.v[res.v.size() - 2].r -= (long long)(t * Ba);
    } else
      break;
  }
  for (int i = 0; i < res.v.size(); ++i)
    res.v[i].i = 0, res.v[i].r = (long long)(res.v[i].r + eps);
  return res;
}
Big Pow(Big a, long long b) {
  Big res(1);
  for (; b; b >>= 1, a = a * a)
    if (b & 1) res = res * a;
  return res;
}
int main() {
  scanf("%s", s);
  n = strlen(s);
  if (n == 1 && s[0] == '1') return puts("1"), 0;
  reverse(s, s + n);
  for (int i = 0; i < n; i += 4) {
    int x = 0;
    for (int j = min(i + 3, n - 1); j >= i; --j)
      x = (x << 3) + (x << 1) + s[j] - 48;
    A.v.push_back(cpx(x, 0));
  }
  long long b = (log10(s[n - 1] - '0') + n - 1) / log10(3) - 1;
  B.init(1);
  if (b >= 0) B = Pow(Big(3), b);
  now = 3 * b;
  while (1) {
    C = B * Big(3);
    if (A <= B * Big(4))
      Min(ans, now + 4);
    else {
      now += 3, B = C;
      continue;
    }
    if (A <= C)
      Min(ans, now + 3);
    else {
      now += 3, B = C;
      continue;
    }
    if (A <= B * Big(2)) Min(ans, now + 2);
    B = C, now += 3;
    if (A <= B) break;
  }
  Min(ans, now);
  printf("%lld\n", ans);
  return 0;
}