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;
struct ceva {
  long double re, im;
  ceva(long double x = 0, long double y = 0) : re(x), im(y) {}
  long double real() { return re; }
  ceva operator+(const ceva &p) { return {p.re + re, p.im + im}; }
  ceva operator-(const ceva &p) { return {re - p.re, im - p.im}; }
  ceva operator*(const ceva &p) {
    return {p.re * re - p.im * im, p.re * im + p.im * re};
  }
  bool operator/=(const long double &p) { re /= p; }
};
vector<long long> n, a, aux, baza;
vector<ceva> v1, v2, v;
string s;
int p, ln, dim, rez, fin = 1e9, log2dim, sg;
long double eps = 1e-14, pi = acos(-1.0);
void citire() {
  std::ios::sync_with_stdio(false);
  cin >> s;
  ln = s.size();
  if (s.size() % 4 != 0) {
    for (int k = 1; k <= 4; k++) s = '0' + s;
  }
  for (int i = s.size() - 1; i >= 3; i -= 4) {
    int val = 0, powe = 1;
    for (int j = 0; j <= 3; j++) {
      val += (s[i - j] - '0') * powe;
      powe *= 10;
    }
    n.push_back(val);
  }
  p = max((int)((ln / log10(3)) - 6), 0);
}
int invers(int val) {
  int rez = 0;
  for (int i = 1; i <= log2dim; i++) {
    rez = rez << 1;
    rez |= (val & 1);
    val = val >> 1;
  }
  return rez;
}
void fft(vector<ceva> &a) {
  int s, m, k, j;
  log2dim = log2(dim);
  for (int i = 0; i < dim; i++) {
    int r = invers(i);
    if (i < r) swap(a[i], a[r]);
  }
  for (s = 1; s <= log2dim; s++) {
    m = (1LL << s);
    long double un;
    if (sg == 1)
      un = (2LL * pi / m);
    else
      un = -(2LL * pi / m);
    ceva wm(cos(un), sin(un));
    for (k = 0; k < dim; k += m) {
      ceva w(1, 0);
      for (j = 0; j < m / 2; j++) {
        ceva u = a[j + k], v = w * a[j + k + m / 2];
        a[j + k] = u + v;
        a[j + k + m / 2] = u - v;
        w = w * wm;
      }
    }
  }
  if (sg == -1)
    for (int i = 0; i < dim; i++) a[i] /= dim;
}
void inm(vector<long long> &a, vector<long long> b) {
  int i, t = 0;
  v1.resize(0);
  for (i = 0; i < a.size(); i++) v1.push_back(a[i]);
  v2.resize(0);
  for (i = 0; i < b.size(); i++) v2.push_back(b[i]);
  dim = max(a.size(), b.size()) * 2;
  i = 0;
  while (dim > (1 << i)) i++;
  dim = (1 << i);
  for (i = v1.size(); i < dim; i++) v1.push_back(0);
  for (i = v2.size(); i < dim; i++) v2.push_back(0);
  sg = 1;
  fft(v1);
  sg = 1;
  fft(v2);
  v.resize(dim);
  for (i = 0; i < dim; i++) v[i] = v1[i] * v2[i];
  sg = -1;
  fft(v);
  a.resize(dim);
  for (i = 0; i < dim; i++) {
    long long x = (long long)round(v[i].real());
    a[i] = (x + t) % 10000;
    t = (x + t) / 10000;
  }
  if (t) a.push_back(t);
  while ((a.size() > 0) && (a.back() == 0)) a.pop_back();
}
vector<long long> inmct(vector<long long> a, long long ct) {
  int t = 0;
  for (int i = 0; i < a.size(); i++) {
    long long x = a[i] * ct;
    a[i] = (x + t) % 10000;
    t = (x + t) / 10000;
  }
  if (t) a.push_back(t);
  return a;
}
void ridica() {
  int b = p;
  baza.resize(0);
  baza.push_back(3);
  a.resize(0);
  a.push_back(1);
  while (b > 0) {
    if (b & 1) inm(a, baza);
    inm(baza, baza);
    b = b >> 1;
  }
}
int maimic(vector<long long> unu, vector<long long> doi) {
  if (unu.size() < doi.size()) return 1;
  if (unu.size() > doi.size()) return 0;
  for (int i = unu.size() - 1; i >= 0; i--)
    if (unu[i] < doi[i])
      return 1;
    else if (unu[i] > doi[i])
      return 0;
  return 0;
}
void solutie() {
  int nrde2;
  while ((a.size() > 0) && (a[a.size() - 1] == 0)) a.pop_back();
  for (nrde2 = 0; nrde2 <= 2; nrde2++) {
    rez = nrde2 * 2 + p * 3;
    aux = inmct(a, (1 << nrde2));
    while (maimic(aux, n)) {
      aux = inmct(aux, 3);
      rez += 3;
    }
    fin = min(fin, rez);
  }
  if (fin <= 0) fin = 1;
  cout << fin;
}
int main() {
  citire();
  ridica();
  solutie();
  return 0;
}