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 read() {
  int v = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    v = v * 10 + c - '0';
    c = getchar();
  }
  return v * f;
}
const int Maxn = 2100005;
const int mod = 998244353;
int qp(int x, int p) {
  int ret = 1;
  while (p) {
    if (p & 1) ret = 1ll * ret * x % mod;
    x = 1ll * x * x % mod;
    p >>= 1;
  }
  return ret;
}
int inv(int x) { return qp(x, mod - 2); }
int rev[Maxn], tmpA[Maxn], tmpB[Maxn];
int tt[Maxn];
void NTT(int X[], int n, int f) {
  for (int i = 1; i < n; i++) {
    rev[i] = rev[i >> 1] >> 1;
    if (i & 1) rev[i] |= n >> 1;
  }
  for (int i = 0; i < n; i++) {
    if (i < rev[i]) swap(X[i], X[rev[i]]);
  }
  for (int i = 2; i <= n; i <<= 1) {
    int wn = qp(3, (mod - 1) / i);
    if (f == -1) wn = inv(wn);
    int s = i >> 1;
    tt[0] = 1;
    for (int j = 1; j < s; j++) tt[j] = 1ll * tt[j - 1] * wn % mod;
    for (int j = 0; j < n; j += i) {
      int w = 1;
      for (int k = j; k < j + s; k++) {
        int u = X[k], v = 1ll * X[k + s] * tt[k - j] % mod;
        X[k] = u + v;
        if (X[k] >= mod) X[k] -= mod;
        X[k + s] = u - v;
        if (X[k + s] < 0) X[k + s] += mod;
      }
    }
  }
  if (f == -1) {
    int iv = inv(n);
    for (int i = 0; i < n; i++) {
      X[i] = 1ll * X[i] * iv % mod;
    }
  }
}
int pw3[23][Maxn], Lg3[23];
int sz3[23];
char c[Maxn];
int N[Maxn], kn;
void Mul(int A[], int B[], int C[], int Sz) {
  int t = 1;
  while (t < Sz) t <<= 1;
  for (int i = 0; i < t; i++) {
    tmpA[i] = B[i];
    tmpB[i] = C[i];
  }
  NTT(tmpA, t, 0);
  NTT(tmpB, t, 0);
  for (int i = 0; i < t; i++) {
    tmpA[i] = 1ll * tmpA[i] * tmpB[i] % mod;
  }
  NTT(tmpA, t, -1);
  for (int i = 0; i < t; i++) A[i] = tmpA[i];
  for (int i = 0; i < t; i++) {
    if (A[i] >= 10) {
      A[i + 1] += A[i] / 10;
      A[i] %= 10;
    }
  }
  assert(A[t] < 10);
}
void Mul2(int A[], int C[], int Sz) {
  int t = 1;
  while (t < Sz) t <<= 1;
  for (int i = 0; i < t; i++) {
    tmpA[i] = C[i];
  }
  NTT(tmpA, t, 0);
  for (int i = 0; i < t; i++) {
    tmpA[i] = 1ll * tmpA[i] * tmpA[i] % mod;
  }
  NTT(tmpA, t, -1);
  for (int i = 0; i < t; i++) A[i] = tmpA[i];
  for (int i = 0; i < t; i++) {
    if (A[i] >= 10) {
      A[i + 1] += A[i] / 10;
      A[i] %= 10;
    }
  }
}
void Mul9(int X[], int sz) {
  for (int i = 0; i < sz; i++) {
    X[i] = X[i] * 9;
  }
  for (int i = 0; i < sz; i++) {
    if (X[i] >= 10) {
      X[i + 1] += X[i] / 10;
      X[i] %= 10;
    }
  }
}
void _init() {
  sz3[0] = 1;
  Lg3[0] = 1;
  pw3[0][0] = 3;
  for (int i = 1; i < 21; i++) {
    Mul2(pw3[i], pw3[i - 1], sz3[i - 1] << 1);
    Lg3[i] = Lg3[i - 1] << 1;
    int nd = (1 << i);
    for (int j = nd; j >= 0; j--) {
      if (pw3[i][j]) {
        sz3[i] = j + 1;
        break;
      }
    }
    while (sz3[i] != nd) {
      Mul9(pw3[i], sz3[i]);
      Lg3[i] += 2;
      for (int j = nd; j >= 0; j--) {
        if (pw3[i][j]) {
          sz3[i] = j + 1;
          break;
        }
      }
    }
  }
}
void Div3(int X[], int &Sz) {
  int rem = 0;
  for (int i = Sz - 1; i >= 0; i--) {
    rem = rem * 10 + X[i];
    tmpA[i] = rem / 3;
    rem %= 3;
  }
  int Ns = 0;
  for (int i = Sz - 1; i >= 0; i--) {
    X[i] = tmpA[i];
    if (X[i]) Ns = max(Ns, i + 1);
  }
  Sz = Ns;
}
void Div2(int X[], int &Sz) {
  int rem = 0;
  for (int i = Sz - 1; i >= 0; i--) {
    rem = rem * 10 + X[i];
    tmpA[i] = rem >> 1;
    rem &= 1;
  }
  int Ns = 0;
  for (int i = Sz - 1; i >= 0; i--) {
    X[i] = tmpA[i];
    if (X[i]) Ns = max(Ns, i + 1);
  }
  Sz = Ns;
}
int BruteLog3(int X[], int Sz) {
  int ret = 0;
  while (1) {
    if (Sz == 0) {
      break;
    }
    ret++;
    Div3(X, Sz);
  }
  return ret;
}
int rem[514], Sr;
void Div(int A[], int SA, const int B[], const int SB) {
  for (int i = SA - 1; i >= SB - 1; i--) {
    while (1) {
      int flag = 0;
      for (int j = i; j > i - SB; j--) {
        if (A[j] < B[j - i + SB - 1]) {
          flag = -1;
          break;
        } else if (A[j] > B[j - i + SB - 1]) {
          break;
        }
      }
      if (A[i + 1]) flag = 0;
      if (flag == -1) break;
      for (int j = i; j > i - SB; j--) {
        A[j] -= B[j - i + SB - 1];
      }
      rem[i - SB + 1]++;
      for (int j = i - SB + 1; j <= i; j++) {
        if (A[j] < 0) {
          A[j] += 10;
          A[j + 1]--;
        }
      }
    }
  }
  for (int i = 513; i >= 0; i--) {
    if (rem[i]) {
      Sr = i + 1;
      break;
    }
  }
}
int Cur[Maxn], Curs, Ct[Maxn];
int DDD;
int Log3(int X[], int Sz) {
  if (Sz <= 20) {
    return BruteLog3(X, Sz);
  }
  int ret = 0;
  if (!Curs) {
    memset(Cur, 0, sizeof(Cur));
    Cur[0] = 1;
    Curs = 1;
    int Rbs = Sz - 2;
    for (int i = 0; i < 21; i++) {
      if (Rbs >> i & 1) {
        memset(Ct, 0, sizeof(Ct));
        ret += Lg3[i];
        Mul(Ct, Cur, pw3[i], sz3[i] + Curs);
        for (int j = 0; j < Maxn; j++) Cur[j] = Ct[j];
        for (int j = 0; j < Maxn; j++) {
          if (Cur[j]) Curs = j + 1;
        }
      }
    }
    while (Curs < Sz - 2) {
      ret += 2;
      Mul9(Cur, Curs);
      for (int i = Maxn - 1; i >= 0; i--) {
        if (Cur[i]) {
          Curs = i + 1;
          break;
        }
      }
    }
    DDD = ret;
  } else
    ret = DDD;
  Div(X, Sz, Cur, Curs);
  int Rd = BruteLog3(rem, Sr);
  return ret + Rd;
}
int tN[Maxn];
int main() {
  _init();
  scanf("%s", c);
  kn = strlen(c);
  for (int i = 0; i < kn; i++) {
    N[i] = c[kn - i - 1] - '0';
  }
  if (kn == 1) {
    int v = N[0];
    if (v < 6) {
      printf("%d\n", v);
      return 0;
    }
  }
  N[0]--;
  int tk = 0;
  for (int i = 0; i < kn; i++) {
    if (N[i] < 0) N[i] += 10, N[i + 1]--;
    if (N[i]) tk = i;
  }
  kn = tk + 1;
  for (int i = 0; i < kn; i++) tN[i] = N[i];
  int res = Log3(N, kn) * 3;
  for (int i = 0; i < kn; i++) N[i] = tN[i];
  Div2(N, kn);
  for (int i = 0; i < kn; i++) tN[i] = N[i];
  res = min(res, Log3(N, kn) * 3 + 2);
  for (int i = 0; i < kn; i++) N[i] = tN[i];
  Div2(N, kn);
  res = min(res, Log3(N, kn) * 3 + 4);
  printf("%d\n", res);
  return 0;
}