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;
using ll = long long;
namespace fft {
struct num {
  long double x, y;
  num() { x = y = 0; }
  num(long double x, long double y) : x(x), y(y) {}
};
inline num operator+(num a, num b) { return num(a.x + b.x, a.y + b.y); }
inline num operator-(num a, num b) { return num(a.x - b.x, a.y - b.y); }
inline num operator*(num a, num b) {
  return num(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
inline num conj(num a) { return num(a.x, -a.y); }
int base = 1;
vector<num> roots = {{0, 0}, {1, 0}};
vector<int> rev = {0, 1};
const long double PI = acosl(-1.0);
void ensure_base(int nbase) {
  if (nbase <= base) return;
  rev.resize(1 << nbase);
  for (int i = 0; i < (1 << nbase); i++) {
    rev[i] = (rev[i >> 1] >> 1) + ((i & 1) << (nbase - 1));
  }
  roots.resize(1 << nbase);
  while (base < nbase) {
    long double angle = 2 * PI / (1 << (base + 1));
    for (int i = 1 << (base - 1); i < (1 << base); i++) {
      roots[i << 1] = roots[i];
      long double angle_i = angle * (2 * i + 1 - (1 << base));
      roots[(i << 1) + 1] = num(cos(angle_i), sin(angle_i));
    }
    base++;
  }
}
void fft(vector<num> &a, int n = -1) {
  if (n == -1) {
    n = a.size();
  }
  assert((n & (n - 1)) == 0);
  int zeros = __builtin_ctz(n);
  ensure_base(zeros);
  int shift = base - zeros;
  for (int i = 0; i < n; i++) {
    if (i < (rev[i] >> shift)) {
      swap(a[i], a[rev[i] >> shift]);
    }
  }
  for (int k = 1; k < n; k <<= 1) {
    for (int i = 0; i < n; i += 2 * k) {
      for (int j = 0; j < k; j++) {
        num z = a[i + j + k] * roots[j + k];
        a[i + j + k] = a[i + j] - z;
        a[i + j] = a[i + j] + z;
      }
    }
  }
}
vector<num> fa, fb;
vector<int> multiply(vector<int> &a, vector<int> &b) {
  int need = a.size() + b.size() - 1;
  int nbase = 0;
  while ((1 << nbase) < need) nbase++;
  ensure_base(nbase);
  int sz = 1 << nbase;
  if (sz > (int)fa.size()) {
    fa.resize(sz);
  }
  for (int i = 0; i < sz; i++) {
    int x = (i < (int)a.size() ? a[i] : 0);
    int y = (i < (int)b.size() ? b[i] : 0);
    fa[i] = num(x, y);
  }
  fft(fa, sz);
  num r(0, -0.25 / sz);
  for (int i = 0; i <= (sz >> 1); i++) {
    int j = (sz - i) & (sz - 1);
    num z = (fa[j] * fa[j] - conj(fa[i] * fa[i])) * r;
    if (i != j) {
      fa[j] = (fa[i] * fa[i] - conj(fa[j] * fa[j])) * r;
    }
    fa[i] = z;
  }
  fft(fa, sz);
  vector<int> res(need);
  long long carry = 0;
  for (int i = 0; i < need; i++) {
    carry += (long long)(fa[i].x + 0.3);
    res[i] = carry % 1000;
    carry /= 1000;
  }
  while (carry > 0) {
    res.push_back(carry % 1000);
    carry /= 1000;
  }
  return res;
}
}  // namespace fft
struct Bigint {
  vector<int> val;
  Bigint(int x = 0) {
    if (x) val.push_back(x);
  }
  void read(const string &s) {
    for (int i = (int)s.size() - 1; i >= 0; i -= 3) {
      val.push_back(int(s[i] - '0'));
      if (i - 1 >= 0) val.back() += 10 * int(s[i - 1] - '0');
      if (i - 2 >= 0) val.back() += 100 * int(s[i - 2] - '0');
    }
  }
  Bigint operator*(Bigint &o) {
    Bigint ans;
    ans.val = fft::multiply(val, o.val);
    return ans;
  }
  Bigint operator*(int o) {
    Bigint ans = *this;
    int carry = 0;
    for (int i = 0; i < (int)ans.val.size(); i++) {
      carry += ans.val[i] * o;
      ans.val[i] = carry % 1000;
      carry /= 1000;
    }
    while (carry > 0) {
      ans.val.push_back(carry % 1000);
      carry /= 1000;
    }
    return ans;
  }
  bool operator>=(const Bigint &o) const {
    if (val.size() != o.val.size()) return val.size() > o.val.size();
    for (int i = (int)val.size() - 1; i >= 0; i--) {
      if (val[i] != o.val[i]) return val[i] > o.val[i];
    }
    return true;
  }
  bool operator<=(const Bigint &o) const { return o >= *this; }
};
Bigint n, t(1);
int main() {
  ios::sync_with_stdio(false);
  string text;
  cin >> text;
  n.read(text);
  if (n <= 4) {
    cout << text << endl;
    return 0;
  }
  int val = ((long double)text.size()) * log(10) / log(3);
  val = max(1, val - 3);
  {
    int e = val;
    Bigint tmp(3);
    while (e) {
      if (e & 1) t = t * tmp;
      tmp = tmp * tmp;
      e /= 2;
    }
  }
  int ans = 1000000000;
  int ans_tmp = val * 3;
  for (int i = 0; i <= 6; i++) {
    if (t >= n) ans = min(ans, ans_tmp);
    if ((t * 2) >= n) ans = min(ans, ans_tmp + 2);
    if ((t * 4) >= n) ans = min(ans, ans_tmp + 4);
    t = t * 3;
    ans_tmp += 3;
  }
  cout << ans << endl;
}