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;
long long MulModL(long long B, long long P, long long M) {
  B %= M;
  P %= M;
  long long R = 0;
  while (P > 0) {
    if ((P & 1ll) == 1) {
      R = (R + B);
      if (R >= M) R -= M;
    }
    P >>= 1ll;
    B = (B + B);
    if (B >= M) B -= M;
  }
  return R;
}
long long MulModD(long long B, long long P, long long M) {
  long long I = ((long double)B * (long double)P / (long double)M);
  long long R = B * P - M * I;
  R = (R % M + M) % M;
  return R;
}
long long BigMod(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = (R * B) % M;
    }
    P /= 2;
    B = (B * B) % M;
  }
  return R;
}
long long BigModML(long long B, long long P, long long M) {
  long long R = 1;
  while (P > 0) {
    if (P % 2 == 1) {
      R = MulModL(R, B, M);
    }
    P /= 2;
    B = MulModL(B, B, M);
  }
  return R;
}
template <class T1>
void deb(T1 e1) {
  cout << e1 << "\n";
}
template <class T1, class T2>
void deb(T1 e1, T2 e2) {
  cout << e1 << " " << e2 << "\n";
}
template <class T1, class T2, class T3>
void deb(T1 e1, T2 e2, T3 e3) {
  cout << e1 << " " << e2 << " " << e3 << "\n";
}
template <class T1, class T2, class T3, class T4>
void deb(T1 e1, T2 e2, T3 e3, T4 e4) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << "\n";
}
template <class T1, class T2, class T3, class T4, class T5>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << "\n";
}
template <class T1, class T2, class T3, class T4, class T5, class T6>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << "\n";
}
template <class T1, class T2, class T3, class T4, class T5, class T6, class T7>
void deb(T1 e1, T2 e2, T3 e3, T4 e4, T5 e5, T6 e6, T7 e7) {
  cout << e1 << " " << e2 << " " << e3 << " " << e4 << " " << e5 << " " << e6
       << " " << e7 << "\n";
}
struct cmplx {
  long double r, i;
  inline cmplx() { r = i = 0.0; }
  inline cmplx(long double x) { r = x, i = 0.0; }
  inline cmplx(long double x, long double y) { r = x, i = y; }
  inline void operator+=(const cmplx &q) { r += q.r, i += q.i; }
  inline void operator-=(const cmplx &q) { r -= q.r, i -= q.i; }
  inline cmplx operator+(const cmplx &q) { return cmplx(r + q.r, i + q.i); }
  inline cmplx operator-(const cmplx &q) { return cmplx(r - q.r, i - q.i); }
  inline cmplx operator*(const cmplx &q) {
    return cmplx(r * q.r - i * q.i, r * q.i + i * q.r);
  }
};
inline void fft(vector<cmplx> &a, bool invert) {
  int n = (int)a.size();
  for (int i = 1, j = 0; i < n; ++i) {
    int bit = n >> 1;
    for (; j >= bit; bit >>= 1) j -= bit;
    j += bit;
    if (i < j) swap(a[i], a[j]);
  }
  for (int len = 2; len <= n; len <<= 1) {
    long double ang = 2 * acos(-1) / len * (invert ? -1 : 1);
    cmplx wlen(cos(ang), sin(ang));
    for (int i = 0; i < n; i += len) {
      cmplx w(1);
      for (int j = 0; j < len / 2; ++j) {
        cmplx u = a[i + j], v = a[i + j + len / 2] * w;
        a[i + j] = u + v;
        a[i + j + len / 2] = u - v;
        w = w * wlen;
      }
    }
  }
  if (invert)
    for (int i = 0; i < n; ++i) a[i].r /= n;
  return;
}
inline void multiply(vector<int> &a, vector<int> &b, vector<int> &r) {
  vector<cmplx> fa(a.begin(), a.end()), fb(b.begin(), b.end());
  size_t n = 1;
  while (n < max(a.size(), b.size())) n <<= 1;
  n <<= 1;
  fa.resize(n), fb.resize(n);
  fft(fa, false), fft(fb, false);
  for (size_t i = 0; i < n; ++i) fa[i] = fa[i] * fb[i];
  fft(fa, true);
  r.clear();
  long long carry = 0;
  for (size_t i = 0; i < n; ++i) {
    long long now = (long long)(fa[i].r + 0.5) + carry;
    carry = now / 10000;
    r.push_back((now % 10000));
  }
  while (carry > 0) {
    r.push_back((carry % 10000));
    carry /= 10000;
  }
  assert(carry == 0);
  return;
}
inline void multiplyLongNum(vector<int> a, vector<int> b, vector<int> &res) {
  reverse(a.begin(), a.end());
  reverse(b.begin(), b.end());
  multiply(a, b, res);
  int n = res.size();
  for (int i = ((int)res.size()) - 1; i > 0; i--) {
    if (res[i] == 0)
      res.pop_back();
    else
      break;
  }
  reverse(res.begin(), res.end());
}
int n;
char st[2000006];
vector<int> num;
inline bool issmall(vector<int> &vt) {
  if (n != vt.size()) return vt.size() < n;
  for (int i = 0; i < n; i++) {
    if (vt[i] < num[i]) return true;
    if (vt[i] > num[i]) return false;
  }
  return false;
}
inline void multiplySmallNum(vector<int> &a, int val, vector<int> &res) {
  vector<int> ret(a.size());
  int carry = 0;
  for (int i = a.size() - 1; i >= 0; i--) {
    ret[a.size() - i - 1] = a[i] * val + carry;
    carry = ret[a.size() - i - 1] / 10000;
    ret[a.size() - i - 1] %= 10000;
  }
  if (carry) ret.push_back(carry);
  res = ret;
  reverse(res.begin(), res.end());
}
int main() {
  scanf("%s", st);
  n = strlen(st);
  if (n == 1 && st[0] <= '3') {
    printf("%c", st[0]);
    return 0;
  }
  num.resize((n + 4 - 1) / 4);
  int pwe[] = {1, 10, 100, 1000, 10000, 100000};
  for (int i = n - 1; i >= 0; i--) {
    int j = (n - i - 1);
    num[j / 4] = num[j / 4] + pwe[j % 4] * (st[i] - '0');
  }
  reverse(num.begin(), num.end());
  n = num.size();
  int pw = (floor(logl(10000) * (n - 1) / logl(3.0))) - 10;
  if (pw <= 0) pw = 0;
  int PW = pw;
  vector<int> vt = {1}, a = {3};
  while (pw > 0) {
    if (pw & 1) multiplyLongNum(a, vt, vt);
    multiplyLongNum(a, a, a);
    pw /= 2;
  }
  vector<int> one, two, zero = vt;
  multiplySmallNum(zero, 2, one);
  multiplySmallNum(one, 2, two);
  int sumone = 2, sumtwo = 4, sumzero = 0;
  while (issmall(zero)) multiplySmallNum(zero, 3, zero), sumzero += 3;
  while (issmall(one)) multiplySmallNum(one, 3, one), sumone += 3;
  while (issmall(two)) multiplySmallNum(two, 3, two), sumtwo += 3;
  printf("%d\n", min(sumone, min(sumtwo, sumzero)) + PW * 3);
  return 0;
}
