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 N = 1500000 + 10;
const int mod = 100;
const double PI = acos(-1.0);
vector<int> a, b;
int v[N];
int sz_v = 0;
int k;
inline bool blank(char ch) {
  return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void read(char *s) {
  char ch = getchar();
  for (; blank(ch); ch = getchar())
    ;
  for (; !blank(ch); ch = getchar()) *s++ = ch;
  *s = 0;
}
struct Complex {
  double x, y;
  Complex(double x = 0.0, double y = 0.0) : x(x), y(y) {}
  Complex operator+(const Complex &b) const {
    return Complex(x + b.x, y + b.y);
  }
  Complex operator-(const Complex &b) const {
    return Complex(x - b.x, y - b.y);
  }
  Complex operator*(const Complex &b) const {
    return Complex(x * b.x - y * b.y, x * b.y + y * b.x);
  }
};
Complex x1[N << 1], x2[N << 1];
void change(Complex y[], int len) {
  for (int i = 1, j = len / 2; i < len - 1; i++) {
    if (i < j) swap(y[i], y[j]);
    int k = len / 2;
    while (j >= k) {
      j -= k;
      k /= 2;
    }
    if (j < k) j += k;
  }
}
void fft(Complex y[], int len, int on) {
  change(y, len);
  for (int h = 2; h <= len; h <<= 1) {
    Complex wn(cos(-on * 2 * PI / h), sin(-on * 2 * PI / h));
    for (int j = 0; j < len; j += h) {
      Complex w(1, 0);
      for (int k = j; k < j + h / 2; k++) {
        Complex u = y[k];
        Complex t = w * y[k + h / 2];
        y[k] = u + t;
        y[k + h / 2] = u - t;
        w = w * wn;
      }
    }
  }
  if (on == -1) {
    for (int i(0); i <= (len - 1); ++i) y[i].x /= len;
  }
}
void mul(vector<int> a, vector<int> b, vector<int> &c) {
  int len = 1;
  int sz1 = a.size(), sz2 = b.size();
  while (len <= sz1 + sz2 - 1) len <<= 1;
  for (int i(0); i <= (sz1 - 1); ++i) x1[i] = Complex(a[i], 0);
  for (int i(sz1); i <= (len); ++i) x1[i] = Complex(0, 0);
  for (int i(0); i <= (sz2 - 1); ++i) x2[i] = Complex(b[i], 0);
  for (int i(sz2); i <= (len); ++i) x2[i] = Complex(0, 0);
  fft(x1, len, 1);
  fft(x2, len, 1);
  for (int i(0); i <= (len - 1); ++i) x1[i] = x1[i] * x2[i];
  fft(x1, len, -1);
  c.clear();
  for (int i(0); i <= (sz1 + sz2 - 2); ++i) {
    c.push_back((int)(x1[i].x + 0.5));
  }
}
void relax(vector<int> &a) {
  int p = 0, sz = (int)a.size();
  for (int i = 0; i < sz || p; ++i) {
    if (i >= sz) a.push_back(0);
    long long cnt = a[i] + p;
    a[i] = cnt % mod;
    p = cnt / mod;
  }
}
void calc(int k) {
  a.push_back(3);
  b.push_back(1);
  for (; k; k >>= 1, mul(a, a, a), relax(a)) {
    if (k & 1) mul(b, a, b), relax(b);
  }
}
void mul3() {
  for (auto &u : b) u *= 3;
  relax(b);
}
int cmp(vector<int> a) {
  int sz_a = (int)a.size();
  if (sz_a < sz_v) return 0;
  if (sz_a > sz_v) return 1;
  for (int i(sz_a - 1); i >= (0); --i) {
    if (a[i] < v[i]) return 0;
    if (a[i] > v[i]) return 1;
  }
  return 1;
}
int check(int x) {
  vector<int> c;
  for (auto u : b) c.push_back(u * x);
  relax(c);
  return cmp(c);
}
int base, ans, len;
char s[N];
void extra() {
  int x = s[0] - '0';
  if (x <= 5)
    printf("%d\n", x);
  else if (x == 6)
    printf("%d\n", 5);
  else
    printf("%d\n", 6);
}
int main() {
  scanf("%s", s);
  len = strlen(s);
  if (len < 2) {
    extra();
    return 0;
  }
  reverse(s, s + len);
  for (int i = 0; i < len; i += 2) {
    int x = s[i] - '0';
    if (i + 1 < len) x = x + (s[i + 1] - '0') * 10;
    v[sz_v++] = x;
  }
  base = (len - 1) * (double)(log(10) / log(3));
  --base;
  calc(base);
  for (ans = base * 3;; ans += 3, mul3()) {
    for (int i(2); i <= (4); ++i)
      if (check(i)) return 0 * printf("%d\n", ans + i);
  }
}