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;
const int maxn = 2e6 + 20, maxm = 2e6 + 10;
vector<int> ans, ss, x;
const double pi = acos(-1.0);
int M, l = 0, r[maxn];
struct Cp {
  double x, y;
  Cp(double _x = 0, double _y = 0) { x = _x, y = _y; }
  Cp operator+(const Cp& rhs) { return Cp(x + rhs.x, y + rhs.y); }
  Cp operator-(const Cp& rhs) { return Cp(x - rhs.x, y - rhs.y); }
  Cp operator*(const Cp& rhs) {
    return Cp(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
  }
} a[maxn], b[maxn], w, xx, w0;
inline void FFT(Cp* A, int f) {
  int i, j, k;
  for (i = 0; i < M; i++)
    if (i < r[i]) swap(A[i], A[r[i]]);
  for (i = 1; i < M; i <<= 1) {
    w.x = cos(pi / i), w.y = sin(pi / i) * f;
    for (j = 0; j < M; j += i << 1) {
      w0.x = 1, w0.y = 0;
      for (k = 0; k < i; ++k) {
        xx = A[j + k];
        A[j + k] = xx + (w0 * A[i + j + k]);
        A[i + j + k] = xx - (w0 * A[i + j + k]);
        w0 = w0 * w;
      }
    }
  }
  if (f == -1)
    for (i = 0; i < M; ++i) A[i].x /= M;
}
vector<int> mul(vector<int> ans, vector<int> x) {
  int len = ans.size() + x.size();
  for (M = 1, l = 0; M <= len; M <<= 1, l++)
    ;
  for (int i = 0; i < ans.size(); i++) a[i].x = ans[i];
  for (int i = 0; i < x.size(); i++) b[i].x = x[i];
  for (int i = 1; i < M; i++) r[i] = (r[i >> 1] >> 1) | ((i & 1) << (l - 1));
  FFT(a, 1);
  FFT(b, 1);
  for (int i = 0; i < M; i++) a[i] = a[i] * b[i];
  FFT(a, -1);
  vector<int> res(len - 1);
  for (int i = 0; i < len - 1; i++) res[i] = (int)(a[i].x + 0.5);
  for (int i = 0; i < M; i++) a[i] = b[i] = {0, 0};
  return res;
}
const int mod = 100;
void recal(vector<int>& x) {
  int now = 0, len = x.size();
  for (int i = 0; i < len || now; i++) {
    if (i >= len) x.push_back(0);
    long long cur = x[i];
    x[i] = (cur + now) % mod;
    now = (cur + now) / mod;
  }
}
void quick_pow(int k) {
  x.push_back(3);
  ans.push_back(1);
  while (k) {
    if (k & 1) ans = mul(ans, x), recal(ans);
    x = mul(x, x), recal(x);
    k >>= 1;
  }
}
void rcal() {
  for (int i = 0; i < ans.size(); i++) ans[i] *= 3;
  recal(ans);
}
char s[maxn];
bool calc(int x) {
  vector<int> now;
  for (int i = 0; i < ans.size(); i++) now.push_back(ans[i] * x);
  recal(now);
  int la = now.size(), lb = ss.size();
  if (la < lb) return 0;
  if (la > lb) return 1;
  for (int i = la - 1; ~i; i--) {
    if (now[i] > ss[i]) return 1;
    if (now[i] < ss[i]) return 0;
  }
  return 1;
}
int as[10] = {0, 1, 2, 3, 4, 5, 5, 6, 6, 6};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%s", s);
  int l = strlen(s);
  reverse(s, s + l);
  if (l == 1) return cout << as[s[0] - '0'] << '\n', 0;
  for (int i = 0; i < l; i += 2) {
    int now = s[i] - '0';
    if (i < l - 1) now += (s[i + 1] - '0') * 10;
    ss.push_back(now);
  }
  int k = (l - 1) * (double)(log(10) / log(3));
  k--;
  int res = 3 * k;
  quick_pow(k);
  for (;; res += 3, rcal()) {
    if (calc(2)) {
      res += 2;
      break;
    } else if (calc(3)) {
      res += 3;
      break;
    } else if (calc(4)) {
      res += 4;
      break;
    }
  }
  cout << res << '\n';
}