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
#include <bits/stdc++.h>
using namespace std;
const int base = 1000;
const double pi = acos(-1);
int rev[(1 << 19) + 10], p;
char s[(1 << 19) + 10 * 3];
vector<long long> a, b, tmp, ans;
struct Complex {
  double a, b;
} f[(1 << 19) + 10];
vector<Complex> W[19], INVW[19];
inline Complex operator+(const Complex &x, const Complex &y) {
  return (Complex){x.a + y.a, x.b + y.b};
}
inline Complex operator-(const Complex &x, const Complex &y) {
  return (Complex){x.a - y.a, x.b - y.b};
}
inline Complex operator*(const Complex &x, const Complex &y) {
  return (Complex){x.a * y.a - x.b * y.b, x.a * y.b + x.b * y.a};
}
inline Complex operator/(const Complex &x, double y) {
  return (Complex){x.a / y, x.b / y};
}
inline Complex Conjugate(const Complex &x) { return (Complex){x.a, -x.b}; }
void prepare() {
  for (int i = 1, d = 0; d < 19; i <<= 1, ++d) {
    W[d].resize(i);
    INVW[d].resize(i);
    for (int k = 0; k < i; ++k) {
      W[d][k] = (Complex){cos(pi * k / i), sin(pi * k / i)};
      INVW[d][k] = Conjugate(W[d][k]);
    }
  }
}
inline void FFT(Complex *f, int n, int opt) {
  vector<Complex> *w = (~opt) ? W : INVW;
  for (int i = 0; i < n; ++i)
    if (i < rev[i]) swap(f[i], f[rev[i]]);
  for (int i = 1, d = 0; i < n; i <<= 1, ++d) {
    for (int p = (i << 1), j = 0; j < n; j += p) {
      for (int k = 0; k < i; ++k) {
        Complex tmp1 = f[j + k], tmp2 = w[d][k] * f[j + i + k];
        f[j + k] = tmp1 + tmp2, f[j + i + k] = tmp1 - tmp2;
      }
    }
  }
  if (!(~opt))
    for (int i = 0; i < n; ++i) f[i] = f[i] / (double)n;
}
inline void pow2(vector<long long> &a) {
  int n = a.size(), bit = 0;
  while ((1 << bit) < n) ++bit;
  ++bit;
  n = 1 << bit;
  rev[0] = 0;
  for (int i = 0; i < n; ++i)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
  for (int i = 0; i < n; ++i)
    if (i < a.size())
      f[i] = (Complex){(double)a[i], 0};
    else
      f[i] = (Complex){0, 0};
  FFT(f, n, 1);
  for (int i = 0; i < n; ++i) f[i] = f[i] * f[i];
  FFT(f, n, -1);
  a.resize(n);
  for (int i = 0; i < n; ++i) a[i] = (long long)(f[i].a + 0.2);
  long long tmp = 0;
  for (int i = 0; i < n; ++i) {
    tmp += a[i];
    a[i] = tmp % base;
    tmp /= base;
  }
  while (tmp) a.push_back(tmp % base), tmp /= base;
  while (((int)a.size()) && (!(a.back()))) a.pop_back();
}
int getn() {
  scanf("%s", s + 1);
  int len = strlen(s + 1);
  for (int pos = len; pos > 0; pos -= 3) {
    int x = 0;
    for (int i = pos - 2; i <= pos; ++i) {
      if (i <= 0) continue;
      x = x * 10 + s[i] - '0';
    }
    b.push_back(x);
  }
  return len;
}
int getp(int len) { return max(0, (int)(len * log(10) / log(3)) - 5); }
void init() {
  prepare();
  p = getp(getn());
}
void mul(vector<long long> &a, int b) {
  long long tmp = 0;
  for (int i = 0; i < a.size(); ++i) {
    tmp += a[i] * b;
    a[i] = tmp % base;
    tmp /= base;
  }
  while (tmp) a.push_back(tmp % base), tmp /= base;
}
vector<long long> qpower(int x, int k) {
  ans.push_back(1);
  int bit = 0;
  while (1 << (bit + 1) <= k) ++bit;
  for (; ~bit; --bit) {
    pow2(ans);
    if (k & (1 << bit)) mul(ans, x);
  }
  return ans;
}
bool ifless(vector<long long> &a, vector<long long> &b) {
  if (a.size() != b.size()) return a.size() < b.size();
  for (int i = a.size() - 1; ~i; --i)
    if (a[i] != b[i]) return a[i] < b[i];
  return 0;
}
void solve() {
  a = qpower(3, p);
  int ans = 1 << 30;
  for (int i = 0; i < 3; ++i) {
    int times = p * 3 + i * 2;
    tmp = a;
    mul(tmp, 1 << i);
    while (ifless(tmp, b)) {
      times += 3;
      mul(tmp, 3);
    }
    ans = min(ans, times);
  }
  ans = max(1, ans);
  printf("%d\n", ans);
}
int main() {
  init();
  solve();
  return 0;
}
