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>
const int mod = 998244353;
char S[1500010];
int N[1500010], A[1 << 21], n, len;
long long pw(long long a, int n = mod - 2) {
  long long b = 1;
  for (; n; n >>= 1) n % 2 ? b = b * a % mod : 1, a = a * a % mod;
  return b;
}
int add(int a, int b) { return a + b >= mod ? a + b - mod : a + b; }
int sub(int a, int b) { return a - b < 0 ? a - b + mod : a - b; }
int ws[1 << 21];
void dft(int* a, int n, bool r = 0) {
  int* w = ws + n / 2;
  w[0] = 1;
  w[1] = pw(3, (mod - 1) / n);
  if (r) w[1] = pw(w[1]);
  for (int i = 2; i < n / 2; i++) w[i] = w[i - 1] * (long long)w[1] % mod;
  for (int i = n / 2; --i;) ws[i] = ws[i * 2];
  w = ws + 1;
  for (int i = 0, j = 0, t; i < n; i++) {
    if (i < j) t = a[i], a[i] = a[j], a[j] = t;
    for (t = n / 2; (j ^= t) < t; t /= 2)
      ;
  }
  for (int i = 1; i < n; w += i, i *= 2)
    for (int j = 0; j < n; j += i << 1)
      for (int k = 0, t; k < i; k++) {
        t = a[i + j + k] * (long long)w[k] % mod;
        a[i + j + k] = sub(a[j + k], t);
        a[j + k] = add(a[j + k], t);
      }
  if (r) {
    long long I = pw(n);
    for (int i = 0; i < n; i++) a[i] = a[i] * I % mod;
  }
}
void car(int* a, int& n) {
  for (; n && !a[n - 1]; n--)
    ;
}
void sqr() {
  int k = 1;
  while (k < n * 2) k *= 2;
  dft(A, k);
  for (int i = 0; i < k; i++) A[i] = 1ll * A[i] * A[i] % mod;
  dft(A, k, 1);
  for (int i = 0; i < k; i++) A[i + 1] += A[i] / 10, A[i] %= 10;
  car(A, n *= 2);
}
void mul() {
  for (int i = 0, c = 0; i <= n; i++) A[i] = (c += A[i] * 3) % 10, c /= 10;
  car(A, ++n);
}
void div(int* a, int& n, int b) {
  for (int i = n, c = 0; i--;) a[i] = (c = c * 10 + a[i]) / b, c %= b;
  car(a, n);
}
void add() {
  N[0]++;
  for (int i = 0; N[i] > 9; i++) N[i + 1]++, N[i] = 0;
  car(N, ++len);
}
bool lt() {
  if (n != len) return n < len;
  for (int i = n; i--;)
    if (A[i] != N[i]) return A[i] < N[i];
  return 0;
}
int main() {
  scanf("%s", S);
  len = strlen(S);
  for (int i = 0; i < len; i++) N[len - i - 1] = S[i] - '0';
  A[0] = n = 1;
  int m = len * log(10) / log(3) + 1, i = 0;
  while (m >> i) i++;
  while (i--) sqr(), m >> i & 1 ? mul(), 1 : 1;
  while (!lt()) div(A, n, 3), m--;
  int ans = m < 0 ? 1 : (m + 1) * 3;
  for (int t = 1; t <= 2; t++) {
    add();
    div(N, len, 2);
    while (!lt()) div(A, n, 3), m--;
    if ((m + 1) * 3 + t * 2 < ans) ans = (m + 1) * 3 + t * 2;
  }
  printf("%d\n", ans);
}