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 std ::fill;
using std ::reverse;
using std ::swap;
using std ::vector;
template <typename T>
T max(T x, T y) {
  return (x > y) ? x : y;
}
template <typename T>
T min(T x, T y) {
  return (x < y) ? x : y;
}
template <typename T>
bool chkmax(T &x, T y) {
  return (x >= y) ? 0 : (x = y, 1);
}
template <typename T>
bool chkmin(T &x, T y) {
  return (x <= y) ? 0 : (x = y, 1);
}
template <typename T>
T read(T &in) {
  in = 0;
  char ch;
  T f = 1;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) in = in * 10 + ch - '0', ch = getchar();
  return in *= f;
}
static const int max1 = 1 << 21 | 1;
static const int B = 1000;
struct cpx {
  double r, i;
  cpx(double _r = 0, double _i = 0) { r = _r, i = _i; }
  cpx conj() { return cpx(r, -i); }
};
cpx operator+(const cpx &a, const cpx &b) { return cpx(a.r + b.r, a.i + b.i); }
cpx operator-(const cpx &a, const cpx &b) { return cpx(a.r - b.r, a.i - b.i); }
cpx operator*(const cpx &a, const cpx &b) {
  return cpx(a.r * b.r - a.i * b.i, a.r * b.i + a.i * b.r);
}
int N, M, L, R[max1];
cpx PolyA[max1], PolyB[max1];
void FFT(cpx *x) {
  static const double PI = acos(-1);
  for (int i = (0), ir = (N - 1); i <= (ir); ++i)
    if (i < R[i]) swap(x[i], x[R[i]]);
  for (int i = 1; i < N; i <<= 1) {
    cpx wn = cpx(cos(PI / i), sin(PI / i));
    for (int j = 0, t = i << 1; j < N; j += t) {
      cpx w = cpx(1, 0);
      for (int k = 0; k < i; ++k, w = w * wn) {
        cpx p = x[j + k], q = w * x[i + j + k];
        x[j + k] = p + q, x[i + j + k] = p - q;
      }
    }
  }
}
void Mul(vector<int> &a, vector<int> &b, vector<int> &c) {
  for (N = 1, L = 0, M = b.size() + c.size(); N <= M; N <<= 1) ++L;
  for (int i = (0), ir = (N - 1); i <= (ir); ++i)
    R[i] = (R[i >> 1] >> 1) | ((i & 1) << (L - 1));
  for (int i = (0), ir = (b.size() - 1); i <= (ir); ++i) PolyA[i].r = b[i];
  for (int i = (0), ir = (c.size() - 1); i <= (ir); ++i) PolyA[i].i = c[i];
  for (int i = (b.size()), ir = (N - 1); i <= (ir); ++i) PolyA[i].r = 0;
  for (int i = (c.size()), ir = (N - 1); i <= (ir); ++i) PolyA[i].i = 0;
  FFT(PolyA);
  for (int i = (0), ir = (N - 1); i <= (ir); ++i) {
    int j = (N - 1) & (N - i);
    cpx ar = (PolyA[i] + PolyA[j].conj()) * cpx(0.5, 0);
    cpx ai = (PolyA[i] - PolyA[j].conj()) * cpx(0, -0.5);
    PolyB[j] = ar * ai;
  }
  FFT(PolyB);
  a.resize(b.size() + c.size() + 1);
  fill(a.begin(), a.end(), 0);
  for (int i = (0), ir = (a.size() - 1); i <= (ir); ++i) {
    long long t = round(PolyB[i].r / N) + a[i];
    a[i] = t % B;
    if (i != a.size() - 1) a[i + 1] += t / B;
  }
  while (a.size() > 1 && !a.back()) a.pop_back();
}
void Mul(vector<int> &a, vector<int> &b, int c) {
  a.resize(b.size() + 1);
  fill(a.begin(), a.end(), 0);
  for (int i = (0), ir = (b.size() - 1); i <= (ir); ++i) {
    a[i] += b[i] * c;
    a[i + 1] += a[i] / B, a[i] %= B;
  }
  while (a.size() > 1 && !a.back()) a.pop_back();
}
bool operator<(const vector<int> &a, const vector<int> &b) {
  if (a.size() != b.size()) return a.size() < b.size();
  for (int i = (a.size() - 1), ir = (0); i >= (ir); --i)
    if (a[i] != b[i]) return a[i] < b[i];
  return 0;
}
bool operator>=(const vector<int> &a, const vector<int> &b) { return !(a < b); }
int n;
char Sn[max1];
vector<int> a, b, c, d, e;
void qpow(int y) {
  b.push_back(1), c.push_back(3);
  for (; y; y >>= 1, Mul(c, c, c))
    if (y & 1) Mul(b, b, c);
}
int main() {
  scanf("%s", Sn);
  n = strlen(Sn);
  if (n == 1) {
    if (Sn[0] == '1') return puts("1"), 0;
  }
  reverse(Sn, Sn + n);
  int w;
  for (int i = (0), ir = (n - 1); i <= (ir); ++i) {
    a.push_back(0);
    for (int j = (0), jr = (w = min(2, n - 1 - i)); j <= (jr); ++j)
      a.back() = a.back() * 10 + (Sn[i + w - j] - '0');
    i += 2;
  }
  w = max(0, (int)((n - 1) * (log(10) / log(3))) - 1);
  qpow(w);
  int Ans = INT_MAX, cc = 3 * w;
  while (b < a) {
    Mul(d, b, 2);
    if (d >= a) chkmin(Ans, cc + 2);
    Mul(d, b, 4);
    if (d >= a) chkmin(Ans, cc + 4);
    Mul(d, b, 3), b = d, cc += 3;
  }
  printf("%d\n", min(Ans, cc));
  return 0;
}