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>
#pragma GCC optimize "-O3"
using namespace std;
const long long ML = 1000;
const int C = 3;
const double PI = acos(-1.0);
int rev(int x, int k) {
  int ans = 0;
  for (int i = 0; i < k; ++i) {
    ans = ans * 2 + (x & 1);
    x >>= 1;
  }
  return ans;
}
void fft(complex<double> *a, int k, int inv) {
  int n = (1 << k);
  for (int i = 0; i < n; ++i) {
    int x = rev(i, k);
    if (x > i) swap(a[x], a[i]);
  }
  for (int bl = 1; bl < n; bl *= 2) {
    double ang = PI / bl;
    if (inv) ang = -ang;
    complex<double> wadd = complex<double>(cos(ang), sin(ang));
    for (int i = 0; i < n; i += 2 * bl) {
      complex<double> w = 1;
      for (int j = i; j < i + bl; ++j, w = w * wadd) {
        complex<double> u = a[j];
        complex<double> v = a[j + bl] * w;
        a[j] = u + v;
        a[j + bl] = u - v;
      }
    }
  }
  if (inv) {
    for (int i = 0; i < n; ++i) a[i] = a[i] / double(n);
  }
}
complex<double> ac[1500000];
complex<double> bc[1500000];
void mult(vector<long long> &a, const vector<long long> &b) {
  int nd = a.size() - 1 + b.size() - 1 + 1;
  int k = 0;
  while ((1 << k) < nd) ++k;
  for (int i = 0; i < (1 << k); ++i) ac[i] = bc[i] = 0;
  for (int i = 0; i < a.size(); ++i) ac[i] = a[i];
  for (int i = 0; i < b.size(); ++i) bc[i] = b[i];
  fft(ac, k, 0);
  fft(bc, k, 0);
  for (int i = 0; i < (1 << k); ++i) ac[i] = ac[i] * bc[i];
  fft(ac, k, 1);
  a.clear();
  for (int i = 0; i < nd; ++i) a.push_back(llround(ac[i].real()));
  long long p = 0;
  for (int i = 0; i < a.size() || p; ++i) {
    if (i >= a.size()) {
      a.push_back(0);
    }
    long long cur = a[i] + p;
    a[i] = cur % ML;
    p = cur / ML;
  }
}
void mult2(vector<long long> &a) {
  int nd = a.size() - 1 + a.size() - 1 + 1;
  int k = 0;
  while ((1 << k) < nd) ++k;
  for (int i = 0; i < (1 << k); ++i) ac[i] = 0;
  for (int i = 0; i < a.size(); ++i) ac[i] = a[i];
  fft(ac, k, 0);
  for (int i = 0; i < (1 << k); ++i) ac[i] = ac[i] * ac[i];
  fft(ac, k, 1);
  a.clear();
  for (int i = 0; i < nd; ++i) a.push_back(llround(ac[i].real()));
  long long p = 0;
  for (int i = 0; i < a.size() || p; ++i) {
    if (i >= a.size()) {
      a.push_back(0);
    }
    long long cur = a[i] + p;
    a[i] = cur % ML;
    p = cur / ML;
  }
}
string get(const vector<long long> &a) {
  string ans;
  for (int i = 0; i < a.size(); ++i) {
    string x = to_string(a[i]);
    reverse(x.begin(), x.end());
    while (x.size() < C) x += "0";
    ans += x;
  }
  while (ans.back() == '0') ans.pop_back();
  reverse(ans.begin(), ans.end());
  return ans;
}
string s;
bool gr(const string &a, const string &b) {
  if (a.size() > b.size()) return 1;
  if (a.size() < b.size()) return 0;
  return a > b;
}
void mul(string &s, int k) {
  reverse(s.begin(), s.end());
  int p = 0;
  for (int i = 0; i < s.size(); ++i) {
    int x = (s[i] - '0') * k + p;
    s[i] = '0' + x % 10;
    p = x / 10;
  }
  if (p) {
    s += '0' + p;
  }
  reverse(s.begin(), s.end());
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> s;
  if (s == "1") {
    cout << 1 << "\n";
    return 0;
  }
  int x = s.size();
  int ndlen = log(10) * x / log(3) - 3;
  ndlen = max(ndlen, 0);
  vector<long long> vv = {1};
  vector<long long> p = {3};
  int now = ndlen;
  for (int i = 0; now; ++i) {
    if ((now >> i) & 1) {
      mult(vv, p);
      now -= (1 << i);
    }
    if (now) mult2(p);
  }
  string t = get(vv);
  string pr1, pr2;
  while (gr(s, t)) {
    pr2 = pr1;
    pr1 = t;
    mul(t, 3);
    ++ndlen;
  }
  int ans = ndlen * 3;
  mul(pr2, 4);
  if (!gr(s, pr2)) {
    ans = min(ans, (ndlen - 2) * 3 + 4);
  }
  mul(pr1, 2);
  if (!gr(s, pr1)) {
    ans = min(ans, (ndlen - 1) * 3 + 2);
  }
  cout << ans << "\n";
  return 0;
}