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 INF = 1000000000;
const int MAX_BIT = 22;
const int MAX = 1 << MAX_BIT >> 1;
const double log10_ = log(10.0);
const double log3_ = log(3.0);
const double PI = acos(-1.0);
const int MAX_POW = 3143855;
const int MAX_THREE_POW = 30;
int dblcmp(double x) {
  if (fabs(x) < 1e-8) return 0;
  return x < 0 ? -1 : 1;
}
int bit[MAX];
int *last = bit;
struct BigNum {
  int len;
  int *dig;
  void clr(int size) {
    len = size;
    dig = last;
    last += size;
    memset(dig, 0, sizeof(int) * size);
  }
  void out() {
    printf("len=%d,", len);
    for (int i = len - 1; i >= 0; i--) {
      printf("%d", dig[i]);
    }
    cout << endl;
  }
};
char str[MAX];
int L;
bool cmp(const int *a, char s[], int plen) {
  int n = L;
  if (plen > n) return true;
  if (plen < n) return false;
  int i;
  for (i = 0; i < n; i++) {
    if (s[i] - '0' != a[n - 1 - i]) {
      return a[n - 1 - i] > s[i] - '0';
    }
  }
  return true;
}
int getC(complex<double> c[], const BigNum &a) {
  int i;
  for (i = 0; i < a.len; i++) {
    c[i] = a.dig[i];
  }
  return a.len;
}
complex<double> ca[MAX], cb[MAX];
vector<complex<double> > iw[MAX_BIT];
vector<complex<double> > w[MAX_BIT];
void fft(complex<double> a[], int n, int dft, const vector<int> &rev,
         vector<complex<double> > w[MAX_BIT]) {
  int i, j, k;
  for (i = 0; i < n; i++) {
    if (i < rev[i]) {
      swap(a[i], a[rev[i]]);
    }
  }
  int bit = 0;
  for (i = 2; i <= n; i <<= 1) {
    bit++;
    for (j = 0; j < n; j += i) {
      for (k = 0; k < (i >> 1); k++) {
        complex<double> H = a[j + k];
        complex<double> G = w[bit][k] * a[j + k + (i >> 1)];
        a[j + k] = H + G;
        a[j + k + (i >> 1)] = H - G;
      }
    }
  }
  if (dft == -1) {
    for (i = 0; i < n; i++) {
      a[i] /= n;
    }
  }
}
vector<int> r[MAX_BIT];
void sqr(BigNum &a, BigNum &ret) {
  int n;
  int tot = 1, bit = 0;
  n = getC(ca, a);
  while (tot < n + n) {
    tot <<= 1;
    bit++;
  }
  int i, j;
  for (i = n; i < tot; i++) {
    ca[i] = 0;
  }
  fft(ca, tot, 1, r[bit], w);
  for (i = 0; i < tot; i++) {
    ca[i] *= ca[i];
  }
  fft(ca, tot, -1, r[bit], iw);
  ret.clr(tot);
  for (i = 0; i < tot; i++) {
    ret.dig[i] += ca[i].real() + 0.5;
    if (ret.dig[i] >= 10) {
      ret.dig[i + 1] += ret.dig[i] / 10;
      ret.dig[i] %= 10;
    }
  }
  ret.len = tot;
  while (ret.len > 1 && ret.dig[ret.len - 1] == 0) {
    ret.len--;
    last--;
  }
}
int getC(complex<double> *c, const int *a, int plen) {
  for (int i = 0; i < plen; i++) {
    c[i] = a[i];
  }
  return plen;
}
void mul(int *a, BigNum &b, int &plen) {
  int n, m;
  int tot = 1, bit = 0;
  n = getC(ca, a, plen);
  m = getC(cb, b);
  while (tot < m + n) {
    tot <<= 1;
    bit++;
  }
  int i, j;
  for (i = n; i < tot; i++) {
    ca[i] = 0;
  }
  for (j = m; j < tot; j++) {
    cb[j] = 0;
  }
  fft(ca, tot, 1, r[bit], w);
  fft(cb, tot, 1, r[bit], w);
  for (i = 0; i < tot; i++) {
    ca[i] *= cb[i];
  }
  fft(ca, tot, -1, r[bit], iw);
  plen = tot;
  for (i = 0; i < plen; i++) {
    a[i] = ca[i].real() + 0.5;
  }
  for (i = 0; i < tot; i++) {
    if (a[i] >= 10) {
      a[i + 1] += a[i] / 10;
      a[i] %= 10;
    }
  }
  while (plen > 1 && a[plen - 1] == 0) {
    plen--;
  }
}
BigNum p3[MAX_THREE_POW];
int product[MAX];
int getThreePow(int three) {
  int plen = 1;
  product[0] = 1;
  int ind = 0;
  while (three) {
    if (three & 1) {
      mul(product, p3[ind], plen);
    }
    ind++;
    three >>= 1;
  }
  return plen;
}
void split(int n, int &two, int &three) {
  two = three = 0;
  two = n / 2;
  if (n & 1) {
    three++;
    two--;
  }
  three += 2 * (two / 3);
  two %= 3;
}
bool calc(int n) {
  int two = 0, three = 0;
  int plen = 1;
  product[0] = 1;
  if (n == 1) {
    return cmp(product, str, plen);
  }
  split(n, two, three);
  plen = getThreePow(three);
  two = 1 << two;
  int i;
  if (two > 1) {
    product[plen] = 0;
    for (i = 0; i < plen; i++) {
      product[i] *= two;
    }
    for (i = 0; i < plen; i++) {
      product[i + 1] += product[i] / 10;
      product[i] %= 10;
    }
    if (product[plen]) {
      product[plen + 1] += product[plen] / 10;
      product[plen] %= 10;
      plen++;
    }
  }
  return cmp(product, str, plen);
}
double getLog(char str[], int n) {
  double ret = 0;
  int i;
  double p = 1;
  for (i = 0; i < n && i < 15; i++) {
    ret += (str[i] - '0') * p;
    p *= 0.1;
  }
  return (n - 1) * log10_ + log(ret);
}
int brute() {
  int low = 1;
  int high = 100 * 3;
  int ans = -1;
  while (low <= high) {
    int mid = low + high >> 1;
    bool tmp = calc(mid);
    if (calc(mid)) {
      ans = mid;
      high = mid - 1;
    } else {
      low = mid + 1;
    }
  }
  return ans;
}
int vp[MAX];
int main() {
  int i, j;
  for (i = 1; i < MAX_BIT; i++) {
    r[i] = vector<int>(1 << i);
    r[i][0] = 0;
    for (j = 1; j < (1 << i); j++) {
      r[i][j] = (r[i][j >> 1] >> 1) | ((j & 1) << i >> 1);
    }
  }
  for (i = 1; i < MAX_BIT; i++) {
    w[i] = vector<complex<double> >(1 << i);
    w[i][0] = 1;
    complex<double> wn = exp(complex<double>(0, 2 * PI / (1 << i)));
    for (j = 1; j < (1 << i); j++) {
      w[i][j] = w[i][j - 1] * wn;
    }
  }
  for (i = 1; i < MAX_BIT; i++) {
    iw[i] = vector<complex<double> >(1 << i);
    iw[i][0] = 1;
    complex<double> iwn = exp(complex<double>(0, -2 * PI / (1 << i)));
    for (j = 1; j < (1 << i); j++) {
      iw[i][j] = iw[i][j - 1] * iwn;
    }
  }
  p3[0].clr(1);
  p3[0].dig[0] = 3;
  for (i = 1; i < MAX_THREE_POW; i++) {
    if ((1 << i) > MAX_POW) break;
    sqr(p3[i - 1], p3[i]);
  }
  scanf("%s", str);
  L = strlen(str);
  if (L <= 18) {
    cout << brute() << endl;
    return 0;
  }
  double aim = getLog(str, L);
  int n3 = aim / log3_;
  int ans = -1;
  int plen = getThreePow(n3 - 1);
  int base = (n3 - 1) * 3;
  int res = 3;
  while (true) {
    int two, three;
    int v = 1;
    split(res, two, three);
    v = 1 << two;
    while (three--) {
      v *= 3;
    }
    for (i = 0; i < plen; i++) {
      vp[i] = product[i] * v;
    }
    while (i < plen + 10) {
      vp[i] = 0;
      i++;
    }
    for (i = 0; i < plen + 10; i++) {
      if (vp[i] >= 10) {
        vp[i + 1] += vp[i] / 10;
        vp[i] %= 10;
      }
    }
    int zlen = plen + 10;
    while (zlen > 1 && vp[zlen - 1] == 0) {
      zlen--;
    }
    if (cmp(vp, str, zlen)) break;
    res++;
  }
  cout << base + res << endl;
  return 0;
}