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 MOD = (int)1e9 + 7;
const int FFTMOD = 1007681537;
const int INF = (int)1e9;
const long long LINF = (long long)1e18;
const long double PI = acos((long double)-1);
const long double EPS = 1e-9;
inline long long gcd(long long a, long long b) {
  long long r;
  while (b) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
inline long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
inline long long fpow(long long n, long long k, int p = MOD) {
  long long r = 1;
  for (; k; k >>= 1) {
    if (k & 1) r = r * n % p;
    n = n * n % p;
  }
  return r;
}
template <class T>
inline int chkmin(T& a, const T& val) {
  return val < a ? a = val, 1 : 0;
}
template <class T>
inline int chkmax(T& a, const T& val) {
  return a < val ? a = val, 1 : 0;
}
inline long long isqrt(long long k) {
  long long r = sqrt(k) + 1;
  while (r * r > k) r--;
  return r;
}
inline long long icbrt(long long k) {
  long long r = cbrt(k) + 1;
  while (r * r * r > k) r--;
  return r;
}
inline void addmod(int& a, int val, int p = MOD) {
  if ((a = (a + val)) >= p) a -= p;
}
inline void submod(int& a, int val, int p = MOD) {
  if ((a = (a - val)) < 0) a += p;
}
inline int mult(int a, int b, int p = MOD) { return (long long)a * b % p; }
inline int inv(int a, int p = MOD) { return fpow(a, p - 2, p); }
inline int sign(long double x) { return x < -EPS ? -1 : x > +EPS; }
inline int sign(long double x, long double y) { return sign(x - y); }
const int MAXF = 1 << 20;
struct cp {
  long double x, y;
  cp(long double x = 0, long double y = 0) : x(x), y(y) {}
  cp operator+(const cp& rhs) const { return cp(x + rhs.x, y + rhs.y); }
  cp operator-(const cp& rhs) const { return cp(x - rhs.x, y - rhs.y); }
  cp operator*(const cp& rhs) const {
    return cp(x * rhs.x - y * rhs.y, x * rhs.y + y * rhs.x);
  }
  cp operator!() const { return cp(x, -y); }
} rts[MAXF + 1];
cp fa[MAXF], fb[MAXF];
cp fc[MAXF], fd[MAXF];
int bitrev[MAXF];
void fftinit() {
  int k = 0;
  while ((1 << k) < MAXF) k++;
  bitrev[0] = 0;
  for (int i = 1; i < MAXF; i++) {
    bitrev[i] = bitrev[i >> 1] >> 1 | ((i & 1) << k - 1);
  }
  long double PI = acos((long double)-1.0);
  cp w = cp(cos(2 * PI / MAXF), sin(2 * PI / MAXF));
  rts[0] = rts[MAXF] = cp(1, 0);
  for (int i = 1; i + i <= MAXF; i++) {
    rts[i] = rts[i - 1] * w;
  }
  for (int i = MAXF / 2 + 1; i < MAXF; i++) {
    rts[i] = !rts[MAXF - i];
  }
}
void dft(cp a[], int n, int sign) {
  int d = 0;
  while ((1 << d) * n != MAXF) d++;
  for (int i = 0; i < n; i++) {
    if (i < (bitrev[i] >> d)) {
      swap(a[i], a[bitrev[i] >> d]);
    }
  }
  for (int len = 2; len <= n; len <<= 1) {
    int delta = MAXF / len * sign;
    for (int i = 0; i < n; i += len) {
      cp *x = a + i, *y = a + i + (len >> 1), *w = sign > 0 ? rts : rts + MAXF;
      for (int k = 0; k + k < len; k++) {
        cp z = *y * *w;
        *y = *x - z, *x = *x + z;
        x++, y++, w += delta;
      }
    }
  }
  if (sign < 0) {
    for (int i = 0; i < n; i++) {
      a[i].x /= n;
      a[i].y /= n;
    }
  }
}
void multiply(int a[], int b[], int na, int nb, long long c[]) {
  int n = na + nb - 1;
  while (n != (n & -n)) n += n & -n;
  for (int i = 0; i < n; i++) fa[i] = fb[i] = cp();
  for (int i = 0; i < na; i++) fa[i] = cp(a[i]);
  for (int i = 0; i < nb; i++) fb[i] = cp(b[i]);
  dft(fa, n, 1);
  for (int i = 0; i < n; i++) fa[i] = fa[i] * fa[i];
  dft(fa, n, -1);
  for (int i = 0; i < n; i++) c[i] = (long long)floor(fa[i].x + 0.5);
}
vector<long long> multiply(vector<int> a, vector<int> b,
                           int mod = (int)1e9 + 7) {
  static int fa[MAXF], fb[MAXF];
  long long fc[MAXF];
  int na = a.size(), nb = b.size();
  for (int i = 0; i < na; i++) fa[i] = a[i];
  for (int i = 0; i < nb; i++) fb[i] = b[i];
  multiply(fa, fb, na, nb, fc);
  int k = na + nb - 1;
  vector<long long> res(k);
  for (int i = 0; i < k; i++) res[i] = fc[i];
  return res;
}
int isless(vector<int>& a, vector<int>& b) {
  if (int((a).size()) != int((b).size()))
    return int((a).size()) < int((b).size());
  for (int i = (int((a).size())) - 1; i >= (0); --i) {
    if (a[i] < b[i]) return 1;
    if (a[i] > b[i]) return 0;
  }
  return 0;
}
void mult(vector<int>& num, int k, int base) {
  int carry = 0;
  for (int& x : num) {
    long long nx = (long long)x * k + carry;
    carry = nx / base;
    x = nx % base;
  }
  if (carry) num.push_back(carry);
}
vector<int> p3(int k, int base) {
  if (!k) {
    return vector<int>(1, 1);
  }
  if (k & 1) {
    vector<int> res = p3(k - 1, base);
    mult(res, 3, base);
    return res;
  }
  vector<int> res = p3(k >> 1, base);
  vector<long long> v = multiply(res, res, base);
  vector<int> v2;
  long long carry = 0;
  for (long long x : v) {
    long long nx = x + carry;
    v2.push_back(nx % base);
    carry = nx / base;
  }
  while (carry) {
    v2.push_back(carry % base);
    carry /= base;
  }
  return v2;
}
void phongthan() {
  fftinit();
  const int block = 3;
  string s;
  cin >> s;
  if (s == "1") {
    cout << 1 << "\n";
    return;
  }
  int st = (int((s).size()) - 1) * (logl(10) / logl(3));
  st = max(0, st - 1);
  reverse((s).begin(), (s).end());
  while (int((s).size()) % block) s.push_back('0');
  vector<int> num;
  for (int i = 0; i < int((s).size()); i += block) {
    int k = 0;
    for (int j = 0; j < block; j++) {
      k = k * 10 + s[i + block - j - 1] - '0';
    }
    num.push_back(k);
  }
  int base = fpow(10, block);
  vector<int> A = p3(st, base);
  int res = INF, cnt = st;
  while (isless(A, num)) {
    vector<int> T = A;
    for (int i = (0); i < (3 + 1); ++i) {
      if (!isless(T, num)) {
        chkmin(res, 3 * cnt + 2 * i);
      }
      mult(T, 2, base);
    }
    mult(A, 3, base);
    cnt++;
  }
  chkmin(res, 3 * cnt);
  cout << res << "\n";
}
int main(int argc, char* argv[]) {
  ios_base::sync_with_stdio(0), cin.tie(0);
  if (argc > 1) {
    assert(freopen(argv[1], "r", stdin));
  }
  if (argc > 2) {
    assert(freopen(argv[2], "wb", stdout));
  }
  phongthan();
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
