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;
pair<int, int> exgcd(int a, int b) {
  if (b == 0) return pair<int, int>(1, 0);
  pair<int, int> p = exgcd(b, a % b);
  return pair<int, int>(p.second, p.first - p.second * (a / b));
}
int inverse(int a, int m) {
  pair<int, int> p = exgcd(a, m);
  while (p.first < 0) p.first += m;
  return p.first;
}
constexpr int pack[][4] = {
    {167772161, 243, 1 << 25, 3},         {469762049, 2187, 1 << 26, 3},
    {998244353, 15311432, 1 << 23, 3},    {1107296257, 1087287097, 1 << 25, 10},
    {1711276033, 969788637, 1 << 25, 29}, {1811939329, 72705542, 1 << 26, 13},
    {2013265921, 440564289, 1 << 27, 31}, {2113929217, 1971140334, 1 << 25, 5}};
constexpr int usepacks[] = {1, 3};
template <int mod, int root, int root_pw>
void real_fft(vector<int>& v, bool invert) {
  int n = v.size();
  int a[n];
  for (int i = 0; i < n; i++) a[i] = v[i];
  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]);
  }
  int ww[n];
  int wi = invert ? inverse(root, mod) : root;
  for (int i = n; i < root_pw; i *= 2) wi = wi * 1LL * wi % mod;
  int t = 1;
  for (int i = 0; i < n; i++) {
    ww[i] = t;
    t = t * 1LL * wi % mod;
  }
  for (int len = 2; len <= n; len *= 2) {
    int k = n / len;
    for (int i = 0; i < n; i += len) {
      int wn = 0;
      for (int j = 0; j < len / 2; j++) {
        unsigned int u = a[i + j], v = a[i + j + len / 2] * 1LL * ww[wn] % mod;
        a[i + j] = u + v >= mod ? u + v - mod : u + v;
        a[i + j + len / 2] = u + mod - v >= mod ? u - v : u + mod - v;
        wn = wn + k;
      }
    }
  }
  if (invert) {
    int nrev = inverse(n, mod);
    for (int i = 0; i < n; i++) a[i] = a[i] * 1LL * nrev % mod;
  }
  for (int i = 0; i < n; i++) v[i] = a[i];
}
template <int n>
void fft(vector<int>& a, bool invert) {
  real_fft<pack[usepacks[n]][0], pack[usepacks[n]][1], pack[usepacks[n]][2]>(
      a, invert);
}
vector<int> multiply(const vector<int>& a, const vector<int>& b) {
  bool sqring = a.size() == b.size() ? a == b : 0;
  vector<int> fa = a, fa2, fb = b, fb2;
  int n = 1;
  while (n < (int)(a.size() + b.size())) n *= 2;
  fa.resize(n);
  fa2 = fa;
  fb.resize(n);
  fb2 = fb;
  int p1 = usepacks[0];
  int p2 = usepacks[1];
  int mod1 = pack[p1][0];
  int mod2 = pack[p2][0];
  fft<0>(fa, false);
  if (sqring)
    fb = fa;
  else
    fft<0>(fb, false);
  for (int i = 0; i < n; ++i) fa[i] = (fa[i] * 1LL * fb[i]) % mod1;
  fft<0>(fa, true);
  fft<1>(fa2, false);
  if (sqring)
    fb2 = fa2;
  else
    fft<1>(fb2, false);
  for (int i = 0; i < n; ++i) fa2[i] = (fa2[i] * 1LL * fb2[i]) % mod2;
  fft<1>(fa2, true);
  int r12 = inverse(mod1, mod2);
  vector<int> res;
  res.resize(n);
  long long int carry = 0;
  for (int i = 0; i < n; ++i) {
    int x1 = fa[i];
    int t = x1 % mod2;
    int x2 = ((fa2[i] + mod2 - t) * 1LL * r12) % mod2;
    carry = x1 + x2 * 1LL * mod1 + carry;
    res[i] = carry % 100;
    carry /= 100;
  }
  while (res.size() > 1 && !res.back()) res.pop_back();
  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 % 100;
    carry = cur / 100;
  }
  while (a.size() > 1 && !a.back()) a.pop_back();
}
void fast_3_pow(int k, vector<int>& ans) {
  ans = {1};
  if (k <= 0) return;
  int r = 0, kk = 0;
  for (int t = k; t > 0; t /= 2) {
    r = (2 * r + t % 2);
    kk++;
  }
  for (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 (int i = ((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;
  int p = s.size();
  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() % 2 != 0) s = "0" + s;
  for (int i = 0; i < (int)s.size(); i++) {
    tmp *= 10;
    tmp += s[i] - '0';
    if ((i + 1) % 2 == 0) {
      n.push_back(tmp);
      tmp = 0;
    }
  }
  reverse(n.begin(), n.end());
  vector<int> v1, vt;
  int k;
  k = max((int)(p * logl(10) / logl(3) - 3), (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)(p * logl(10) / logl(3) - 3), (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)(p * logl(10) / logl(3) - 3), (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;
}
