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;
using VI = vector<int>;
namespace fft {
int mPow(int a, int x, int ans = 1) {
  for (; x; x >>= 1, a = (long long)a * a % 998244353)
    if (x & 1) ans = (long long)ans * a % 998244353;
  return ans;
}
const int root = 31;
const int root_1 = mPow(root, 998244353 - 2);
void fft(VI& a, bool invert) {
  int n = a.size();
  int PW = mPow(invert ? root_1 : root, (998244353 - 1) / n);
  for (int m = n, h; h = m / 2, m >= 2;
       PW = (long long)PW * PW % 998244353, m = h) {
    for (int i = 0, w = 1; i < h; i++, w = (long long)w * PW % 998244353)
      for (int j = i, k, x; j < n; j += m) {
        k = j + h;
        ((x = a[j] - a[k]) < 0) && (x += 998244353);
        ((a[j] = a[j] + a[k]) >= 998244353) && (a[j] -= 998244353);
        a[k] = (long long)w * x % 998244353;
      }
  }
  for (int i = 0, j = 1; j < n - 1; j++) {
    for (int k = n / 2; k > (i ^= k); k >>= 1)
      ;
    if (j < i) swap(a[i], a[j]);
  }
  if (invert) {
    int rev = mPow(n, 998244353 - 2);
    for (int i = 0; i < n; i++) {
      a[i] = (long long)a[i] * rev % 998244353;
    }
  }
}
VI multiply(const VI& a, const VI& b, bool ok = false) {
  if (ok) {
    int n = 1 << (32 - __builtin_clz(a.size() + b.size() - 1));
    VI na = a;
    na.resize(n);
    fft(na, false);
    for (int i = 0; i < n; ++i) na[i] = (long long)na[i] * na[i] % 998244353;
    fft(na, true);
    return na;
  }
  int n = 1 << (32 - __builtin_clz(a.size() + b.size() - 1));
  VI na = a, nb = b;
  na.resize(n);
  nb.resize(n);
  fft(na, false);
  fft(nb, false);
  for (int i = 0; i < n; ++i) na[i] = (long long)na[i] * nb[i] % 998244353;
  fft(na, true);
  return na;
}
};  // namespace fft
inline void norm(VI& A) {
  for (int i = 0; i < A.size(); i++) {
    if (A[i] > 9) {
      if (i + 1 == A.size()) A.push_back(0);
      A[i + 1] += A[i] / 10;
      A[i] %= 10;
    }
  }
  while (!A.back()) A.pop_back();
}
inline void sq(VI& A) {
  A = fft ::multiply(A, A, 1);
  norm(A);
}
inline VI operator*(const VI& A, int B) {
  VI ans = A;
  for (auto& r : ans) r *= B;
  norm(ans);
  return ans;
}
inline VI pow3(int x) {
  if (!x) return VI(1, 1);
  VI ans = pow3(x >> 1);
  sq(ans);
  if (x & 1) ans = ans * 3;
  return ans;
}
inline bool operator<(const VI& a, const VI& b) {
  if (a.size() != b.size()) return a.size() < b.size();
  for (int i = a.size(); i--;)
    if (a[i] != b[i]) return a[i] < b[i];
  return 0;
}
VI read(VI& ans) {
  for (char c; ~scanf(" %c", &c); ans.push_back(c - '0'))
    ;
  reverse(ans.begin(), ans.end());
  return ans;
}
int main() {
  VI n, t;
  read(n);
  int ans = 1e9, b;
  t = pow3(b = max((log(10) * (n.size() - 1) - log(4)) / log(3) - 1, 0.));
  for (; t * 4 < n; t = t * 3, b++)
    ;
  ans = min(ans, b * 3 + 4);
  for (; t * 2 < n; b = b + 1, t = t * 3)
    ;
  ans = min(ans, b * 3 + 2);
  for (; t < n; b = b + 1, t = t * 3)
    ;
  ans = min(ans, b * 3);
  cout << max(ans, 1) << endl;
  return 0;
}