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 K = 21, N = 1 << K;
struct cmp {
  double x, y;
  cmp(double _x = 0, double _y = 0) : x(_x), y(_y) {}
};
inline cmp operator+(cmp a, cmp b) { return cmp(a.x + b.x, a.y + b.y); }
inline cmp operator-(cmp a, cmp b) { return cmp(a.x - b.x, a.y - b.y); }
inline cmp operator*(cmp a, cmp b) {
  return cmp(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
inline cmp conj(cmp a) { return cmp(a.x, -a.y); }
string n;
int p, ans;
cmp poW[N], f[N];
int rev[N], nd, num[N], td, tgt[N];
void init() {
  poW[0] = cmp(1, 0);
  double a1 = 8 * atan(1) / N;
  for (int i = 1; i < N; i++) {
    double a = a1 * i;
    poW[i] = cmp(cos(a), sin(a));
    rev[i] = (i & 1) << K - 1 | rev[i >> 1] >> 1;
  }
}
void mul(int x) {
  int car = 0;
  for (int i = 0; i < nd; i++) {
    car += num[i] * x;
    num[i] = car % 10;
    car /= 10;
  }
  while (car) {
    num[nd++] = car % 10;
    car /= 10;
  }
}
void div(int x) {
  int rem = 0;
  for (int i = nd - 1; i >= 0; i--) {
    rem = rem * 10 + num[i];
    num[i] = rem / x;
    rem %= x;
  }
  assert(rem == 0);
  while (nd && !num[nd - 1]) {
    nd--;
  }
}
void fft(int k) {
  int n = 1 << k, sh = K - k;
  for (int i = 0; i < n; i++) {
    int j = rev[i] >> sh;
    if (i < j) swap(f[i], f[j]);
  }
  for (int k = 1, sh = K - 1; k < n; k <<= 1, sh--) {
    for (int i = 0; i < n; i += k << 1) {
      for (int j = 0; j < k; j++) {
        int l = i + j, r = l + k;
        cmp z = f[r] * poW[j << sh];
        f[r] = f[l] - z;
        f[l] = f[l] + z;
      }
    }
  }
}
void pow3(int x) {
  nd = num[0] = 1;
  for (int k = 0, n = 1, b = K; b >= 0; b--) {
    for (nd <<= 1; n < nd; k++, n <<= 1)
      ;
    for (int i = 0; i < n; i++) {
      f[i] = cmp(num[i], 0);
    }
    fft(k);
    for (int i = 0; i < n; i++) {
      f[i] = f[i] * f[i];
      f[i].y = -f[i].y;
    }
    fft(k);
    for (int i = 0; i < n; i++) {
      num[i] = f[i].x / n + 0.5;
    }
    for (; nd && !num[nd - 1]; nd--)
      ;
    mul(1);
    if (x >> b & 1) mul(3);
  }
}
bool small() {
  for (int i = max(nd, td) - 1; i >= 0; i--) {
    if (num[i] < tgt[i]) return true;
    if (num[i] > tgt[i]) return false;
  }
  return false;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  init();
  cin >> n;
  if (n == "1") {
    cout << 1 << '\n';
    return 0;
  }
  td = n.length();
  for (int i = 0; i < td; i++) {
    tgt[i] = n[td - 1 - i] - '0';
  }
  pow3(p = max(td / log10(3.0L) - 3.5L, 0.0L));
  ans = p * 3;
  while (small()) {
    if (ans <= 3) {
      num[0] = ans + 1;
    } else if (ans % 3 == 0) {
      div(3);
      mul(4);
    } else {
      div(2);
      mul(3);
    }
    ans++;
  }
  cout << ans << '\n';
}