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;
int Pow(long long a, int x, int mod) {
  long long res = 1;
  while (x) {
    if (x & 1) (res *= a) %= mod;
    (a *= a) %= mod;
    x >>= 1;
  }
  return res;
}
const long double PI = acos(-1.0);
struct ccc {
  long double real, imag;
  ccc() {}
  ccc(long double real_, long double imag_) : real(real_), imag(imag_) {}
  friend inline ccc operator+(const ccc &lhs, const ccc &rhs) {
    return ccc(lhs.real + rhs.real, lhs.imag + rhs.imag);
  }
  friend inline ccc operator-(const ccc &lhs, const ccc &rhs) {
    return ccc(lhs.real - rhs.real, lhs.imag - rhs.imag);
  }
  friend inline ccc operator*(const ccc &lhs, const ccc &rhs) {
    return ccc(lhs.real * rhs.real - lhs.imag * rhs.imag,
               lhs.real * rhs.imag + lhs.imag * rhs.real);
  }
};
inline ccc conj(ccc &a) { return ccc(a.real, -a.imag); }
inline void FFT(ccc *a, int n, int rev) {
  for (int i = 0, j = 0; i < n; ++i) {
    if (i > j) swap(a[i], a[j]);
    for (int k = n >> 1; (j ^= k) < k; k >>= 1)
      ;
  }
  for (int i = 2; i <= n; i <<= 1) {
    int m = i >> 1;
    ccc g(cos(PI / m), rev * sin(PI / m));
    for (int j = 0; j < n; j += i) {
      ccc w(1, 0);
      for (int k = 0; k != m; k++) {
        ccc z = a[j + m + k] * w;
        a[j + m + k] = a[j + k] - z;
        a[j + k] = a[j + k] + z;
        w = w * g;
      }
    }
  }
  if (rev == -1) {
    for (int i = 0; i < n; i++) a[i].real /= n;
  }
}
ccc A[1 << 20], B[1 << 20], C[1 << 20];
char s[1 << 21];
int n, ans = 1e9;
int base = 10000;
struct BigInt {
  int len;
  long long a[1 << 19];
  BigInt() {
    len = 0;
    memset(a, 0, sizeof(a));
  }
  void one() {
    len = 1;
    a[0] = 1;
  }
  void init(const char *s) {
    len = 0;
    memset(a, 0, sizeof(a));
    int n = strlen(s);
    for (int i = n - 1; i >= 0; i -= 4) {
      int tmp = 0;
      for (int j = max(0, i - 3); j <= i; ++j) {
        tmp *= 10;
        tmp += s[j] - '0';
      }
      a[len++] = tmp;
    }
  }
  bool operator<(const BigInt &B) const {
    if (len != B.len) return len < B.len;
    for (int i = len - 1; i >= 0; --i) {
      if (a[i] < B.a[i]) return 1;
      if (a[i] > B.a[i]) return 0;
    }
    return 0;
  }
  BigInt operator*(const int &b) const {
    BigInt res = *this;
    res.a[len] = 0;
    for (int i = 0; i < res.len; ++i) res.a[i] *= b;
    for (int i = 0; i < res.len; ++i) {
      res.a[i + 1] += res.a[i] / base;
      res.a[i] %= base;
    }
    if (res.a[len]) res.len++;
    return res;
  }
  BigInt &operator*=(const BigInt &b) {
    int L = 1;
    while (L <= len + b.len) L <<= 1;
    for (int i = 0; i < L; ++i) A[i] = B[i] = ccc(0, 0);
    for (int i = 0; i < len; ++i) A[i] = ccc(a[i], 0);
    for (int i = 0; i < b.len; ++i) B[i] = ccc(b.a[i], 0);
    FFT(A, L, 1);
    FFT(B, L, 1);
    for (int i = 0; i < L; ++i) C[i] = A[i] * B[i];
    FFT(C, L, -1);
    len = L;
    a[len] = 0;
    for (int i = 0; i < L; ++i) a[i] = C[i].real + 0.5;
    for (int i = 0; i < L; ++i) {
      a[i + 1] += a[i] / base;
      a[i] %= base;
    }
    while (a[len - 1] == 0) --len;
    return *this;
  }
  void print() {
    for (int i = len - 1; i >= 0; --i) cout << a[i] << "/";
    cout << endl;
  }
} S, P, Q, T;
int e;
int main() {
  scanf("%s", s + 1);
  n = strlen(s + 1);
  if (n == 1 && s[1] == '1') return puts("1");
  S.init(s + 1);
  e = (n - 1) * log(10) / log(3) - 2;
  e = max(e, 0);
  P.one();
  Q.one();
  Q = Q * 3;
  while (e) {
    if (e & 1) P *= Q;
    Q *= Q;
    e >>= 1;
  }
  e = (n - 1) * log(10) / log(3) - 2;
  e = max(e, 0);
  while (P < S) {
    T = P * 2;
    if (!(T < S)) ans = min(ans, 2 + e * 3);
    T = T * 2;
    if (!(T < S)) ans = min(ans, 4 + e * 3);
    e++;
    P = P * 3;
  }
  ans = min(ans, e * 3);
  cout << ans;
}