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 = 2333333;
const int mod = 998244353, G = 3, invG = 332748118;
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int mul(int x, int y) { return 1LL * x * y % mod; }
int sub(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int getinv(int x) { return x <= 1 ? 1 : mul(mod - mod / x, getinv(mod % x)); }
int fpow(int x, int y) {
  int res = 1;
  while (y) {
    if (y & 1) res = mul(res, x);
    x = mul(x, x);
    y >>= 1;
  }
  return res;
}
int len, rev[N];
void init(int n) {
  len = 1;
  rev[0] = 0;
  int L = 0;
  while (len <= n) len <<= 1, L++;
  for (int i = 1; i < len; ++i) rev[i] = rev[i >> 1] >> 1 | (i & 1) << (L - 1);
}
void NTT(int *a, int tp) {
  for (int i = 0; i < len; ++i) {
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  }
  for (int k = 1; k < len; k <<= 1) {
    int wn = fpow(tp == 1 ? G : invG, (mod - 1) / (k << 1));
    for (int i = 0; i < len; i += k << 1) {
      for (int j = 0, w = 1; j < k; ++j, w = mul(w, wn)) {
        int x = a[i + j], y = mul(w, a[i + j + k]);
        a[i + j] = add(x, y);
        a[i + j + k] = sub(x, y);
      }
    }
  }
  if (tp == -1) {
    int invn = getinv(len);
    for (int i = 0; i < len; ++i) a[i] = mul(a[i], invn);
  }
}
int f[N], g[N];
struct BigInt {
  static const int BASE = 100;
  static const int WIDTH = 2;
  vector<int> s;
  BigInt(int num = 0) {
    s.clear();
    do {
      s.push_back(num % BASE), num /= BASE;
    } while (num > 0);
  }
  BigInt(string str) {
    s.clear();
    int x, len = (str.length() - 1) / WIDTH + 1;
    for (int i = 0; i < len; i++) {
      int cl = str.length() - i * WIDTH;
      int op = max(0, cl - WIDTH);
      sscanf(str.substr(op, cl - op).c_str(), "%d", &x);
      s.push_back(x);
    }
    clean();
  }
  void clean() {
    while (s.size() > 1 && !s.back()) s.pop_back();
  }
  BigInt operator*(int b) const {
    BigInt c;
    c.s.clear();
    int len = s.size() + 3;
    for (int i = 0; i < len; i++) f[i] = 0;
    for (int i = 0; i < (int)s.size(); i++) f[i] = s[i] * b;
    for (int i = 0; i < len; i++) {
      if (f[i] >= BASE) f[i + 1] += f[i] / BASE, f[i] %= BASE;
      c.s.push_back(f[i]);
    }
    c.clean();
    return c;
  }
  void operator*=(const BigInt &b) {
    init(s.size() + b.s.size());
    for (int i = 0; i < len; i++) f[i] = g[i] = 0;
    for (int i = 0; i < (int)s.size(); i++) f[i] = s[i];
    for (int i = 0; i < (int)b.s.size(); i++) g[i] = b.s[i];
    NTT(f, 1);
    NTT(g, 1);
    for (int i = 0; i < len; i++) f[i] = mul(f[i], g[i]);
    NTT(f, -1);
    s.clear();
    for (int i = 0; i < len; i++) {
      if (f[i] >= BASE) f[i + 1] += f[i] / BASE, f[i] %= BASE;
      s.push_back(f[i]);
    }
    clean();
  }
  void sqr() {
    init(2 * s.size());
    for (int i = 0; i < len; i++) f[i] = 0;
    for (int i = 0; i < (int)s.size(); i++) f[i] = s[i];
    NTT(f, 1);
    for (int i = 0; i < len; i++) f[i] = mul(f[i], f[i]);
    NTT(f, -1);
    s.clear();
    for (int i = 0; i < len; i++) {
      if (f[i] >= BASE) f[i + 1] += f[i] / BASE, f[i] %= BASE;
      s.push_back(f[i]);
    }
    clean();
  }
  bool operator<=(const BigInt &b) const {
    if (s.size() != b.s.size()) return s.size() < b.s.size();
    for (int i = s.size() - 1; i >= 0; i--) {
      if (s[i] != b.s[i]) return s[i] < b.s[i];
    }
    return 1;
  }
};
double getlog(int x, int y) { return log(y) / log(x); }
BigInt gfpow(int x, int y) {
  BigInt res = 1, xx(x);
  while (y) {
    if (y & 1) res *= xx;
    xx.sqr();
    y >>= 1;
  }
  return res;
}
int p;
BigInt pow3p;
int pow3[] = {1, 3, 9, 27, 81, 243};
BigInt calc(int x) {
  if (x <= 2)
    return x;
  else if (x % 3 == 0)
    return pow3p * pow3[x / 3 - p];
  else if (x % 3 == 1)
    return pow3p * (pow3[x / 3 - 1 - p] * 4);
  else
    return pow3p * (pow3[x / 3 - p] * 2);
}
signed main() {
  string s;
  cin >> s;
  BigInt n(s);
  int len = 3 * ((s.size() - 1) * getlog(3, 10) + getlog(3, s.front() - '0'));
  p = max(0, len / 3 - 1);
  pow3p = gfpow(3, p);
  for (int i = len;; ++i) {
    if (n <= calc(i)) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}