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;
class base {
 public:
  long double a, b;
  base(void) {
    a = 0;
    b = 0;
  }
  base(long double _a, long double _b) {
    a = _a;
    b = _b;
  }
  base(long double _a) {
    a = _a;
    b = 0;
  }
  base operator*(const base& b2) {
    base ret(a * b2.a - b * b2.b, b * b2.a + a * b2.b);
    return ret;
  }
  base operator+(const base& b2) {
    base ret(a + b2.a, b + b2.b);
    return ret;
  }
  base operator-(const base& b2) {
    base ret(a - b2.a, b - b2.b);
    return ret;
  }
  base operator/(const base& b2) {
    long double c = b2.a, d = b2.b;
    base ret((a * c + b * d) / (c * c + d * d),
             (b * c - a * d) / (c * c + d * d));
    return ret;
  }
  void operator*=(const base& b2) {
    long double tmp = a * b2.a - b * b2.b;
    b = b * b2.a + a * b2.b;
    a = tmp;
  }
  void operator/=(const base& b2) {
    long double c = b2.a, d = b2.b;
    long double tmp = (a * c + b * d) / (c * c + d * d);
    b = (b * c - a * d) / (c * c + d * d);
    a = tmp;
  }
  inline long double real(void) { return a; }
};
void fft(vector<base>& 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]);
  }
  base ww[n];
  long double ang = 2 * 3.14159265358979323846l / n * (invert ? -1 : 1);
  base wi(cos(ang), sin(ang));
  ww[0] = 1;
  for (int i = 1; i < n; i++) {
    ww[i] = ww[i / 2] * ww[i / 2];
    if (i % 2 == 1) ww[i] *= wi;
  }
  for (int len = 2; len <= n; len <<= 1) {
    int k = n / len;
    for (int i = 0; i < n; i += len) {
      int wn = 0;
      for (int j = 0; j < len / 2; ++j) {
        base u = a[i + j], v = a[i + j + len / 2] * ww[wn];
        a[i + j] = u + v;
        a[i + j + len / 2] = u - v;
        wn += k;
      }
    }
  }
  if (invert)
    for (int i = 0; i < n; ++i) a[i] /= n;
}
vector<int> multiply(const vector<int>& a, const vector<int>& b) {
  vector<base> fa(a.begin(), a.end());
  size_t n = 1;
  while (n < (a.size() + b.size())) n <<= 1;
  fa.resize(n);
  vector<int> res;
  fft(fa, false);
  for (size_t i = 0; i < n; ++i) fa[i] *= fa[i];
  fft(fa, true);
  res.resize(n);
  long long int carry = 0;
  for (size_t i = 0; i < n; ++i) {
    carry += (long long int)(fa[i].real() + 0.5);
    res[i] = carry % 1000;
    carry /= 1000;
  }
  int i;
  for (i = n - 1; i > 0; i--) {
    if (res[i] != 0) break;
  }
  res.resize(i + 1);
  return res;
}
void small_mult(vector<int>& a, int b) {
  int carry = 0;
  for (int i = 0; i < (int)a.size() || carry; i++) {
    if (i == (int)a.size()) a.push_back(0);
    int cur = carry + a[i] * b;
    a[i] = cur % 1000;
    carry = cur / 1000;
  }
  while (a.size() > 1 && !a.back()) a.pop_back();
}
void fast_3_pow(long long int k, vector<int>& ans) {
  ans = {1};
  if (k <= 0) return;
  long long int r = 0, kk = 0;
  for (long long int t = k; t > 0; t /= 2) {
    r = (2 * r + t % 2);
    kk++;
  }
  for (long long int i = 0; i < kk; i++) {
    ans = multiply(ans, ans);
    if (r % 2) small_mult(ans, 3);
    r /= 2;
  }
}
bool first_is_BE(vector<int>& v1, vector<int>& v2) {
  if (v1.size() > v2.size()) return 1;
  if (v1.size() < v2.size()) return 0;
  for (long long int i = ((long long int)v1.size()) - 1; i >= 0; i--) {
    if (v1[i] > v2[i]) return 1;
    if (v1[i] < v2[i]) return 0;
  }
  return 1;
}
int main() {
  ios::sync_with_stdio(0);
  string s;
  cin >> s;
  if (s == "1") {
    cout << "1";
    return 0;
  }
  if (s == "2") {
    cout << "2";
    return 0;
  }
  if (s == "3") {
    cout << "3";
    return 0;
  }
  if (s == "4") {
    cout << "4";
    return 0;
  }
  if (s == "5") {
    cout << "5";
    return 0;
  }
  if (s == "6") {
    cout << "5";
    return 0;
  }
  if (s == "7") {
    cout << "6";
    return 0;
  }
  if (s == "8") {
    cout << "6";
    return 0;
  }
  if (s == "9") {
    cout << "6";
    return 0;
  }
  vector<int> n;
  int tmp = 0;
  while (s.size() % 3 != 0) s = "0" + s;
  for (int i = 0; i < (int)s.size(); i++) {
    tmp *= 10;
    tmp += s[i] - '0';
    if ((i + 1) % 3 == 0) {
      n.push_back(tmp);
      tmp = 0;
    }
  }
  reverse(n.begin(), n.end());
  vector<int> v1, vt;
  int k;
  k = max((int)(s.size() * logl(10) / logl(3) - 8), (int)0);
  fast_3_pow(k, v1);
  vt = v1;
  small_mult(v1, 4);
  while (1) {
    if (first_is_BE(v1, n)) {
      break;
    }
    k++;
    small_mult(v1, 3);
  }
  int ans3 = 3 * k + 4;
  k = max((int)(s.size() * logl(10) / logl(3) - 8), (int)0);
  v1 = vt;
  while (1) {
    if (first_is_BE(v1, n)) {
      break;
    }
    k++;
    small_mult(v1, 3);
  }
  int ans1 = 3 * k;
  k = max((int)(s.size() * logl(10) / logl(3) - 8), (int)0);
  v1 = vt;
  small_mult(v1, 2);
  while (1) {
    if (first_is_BE(v1, n)) {
      break;
    }
    k++;
    small_mult(v1, 3);
  }
  int ans2 = 3 * k + 2;
  cout << min(min(ans1, ans2), ans3);
  return 0;
}