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;
using cd = complex<double>;
using vi = vector<int>;
const double PI = acos(-1.0);
const int RADIX = 1000;
const int N = 1 << 19;
const double LOG_RADIX = log(RADIX);
const double LOG_3 = log(3.0);
istream& operator>>(istream& in, vi& r) {
  string s;
  in >> s;
  reverse((s).begin(), (s).end());
  while (int((s).size()) % 3) s += '0';
  r.resize(int((s).size()) / 3);
  for (decltype(0) i(0), _B_i(int((r).size())); i < _B_i; ++i)
    for (decltype(0) j(0), _B_j(3); j < _B_j; ++j)
      r[i] = r[i] * 10 + s[i * 3 + 2 - j] - '0';
  return in;
}
cd W[N];
template <bool Inv>
void fft(cd* p, int n) {
  n /= 2;
  for (int i = 0, j = n; i < n; ++i, ++j) {
    cd x = p[i], y = p[j];
    p[i] = (x + y);
    p[j] = (x - y) * (Inv ? W[j] : conj(W[j]));
  }
  if (n > 1) {
    fft<Inv>(p, n);
    fft<Inv>(p + n, n);
  }
}
template <class first>
void bitrev(first* a, int n) {
  for (int i = 0, j = 0, k; i < n; ++i) {
    if (i < j) swap(a[i], a[j]);
    for (k = n; j & (k /= 2);)
      ;
    j += 3 * k - n;
  }
}
void sqr(vi& a) {
  int n = 2 * int((a).size()) - 1;
  for (; n & n - 1; n = (n | n - 1) + 1)
    ;
  vector<cd> af(n);
  for (decltype(0) i(0), _B_i(int((a).size())); i < _B_i; ++i) af[i] = a[i];
  fft<0>(af.data(), n);
  bitrev(af.data(), n);
  for (decltype(0) i(0), _B_i(n); i < _B_i; ++i) af[i] *= af[i];
  fft<1>(af.data(), n);
  bitrev(af.data(), n);
  const double invN = 1.0 / n;
  a.resize(n);
  int64_t carry = 0;
  for (decltype(0) i(0), _B_i(n); i < _B_i; ++i) {
    carry += (int64_t)(af[i].real() * invN + 0.5);
    a[i] = carry % RADIX;
    carry /= RADIX;
  }
  if (carry) a.push_back((int)carry);
  while (int((a).size()) && a.back() == 0) a.pop_back();
}
template <int b>
void mul(vi& a) {
  int carry = 0;
  for (int& x : a) {
    carry += x * b;
    x = carry % RADIX;
    carry /= RADIX;
  }
  if (carry) a.push_back(carry);
}
template <int b>
void div(vi& a) {
  int x = 0;
  for (int i = int((a).size()); i-- > 0;) {
    x = x * RADIX + a[i];
    a[i] = x / b;
    x %= b;
  }
  if (x) ++a[0];
  while (int((a).size()) && a.back() == 0) a.pop_back();
}
int cmp(const vi& a, const vi& b) {
  if (int((a).size()) != int((b).size()))
    return int((a).size()) - int((b).size());
  for (int i = int((a).size()); i-- > 0;)
    if (a[i] != b[i]) return a[i] - b[i];
  return 0;
}
int main() {
  ios::sync_with_stdio(false);
  for (decltype(0) i(0), _B_i(N / 2); i < _B_i; ++i)
    W[i + N / 2] = polar(1.0, (2 * PI / N) * i);
  for (int i = N / 2; i-- > 0; W[i] = W[2 * i])
    ;
  vi a;
  cin >> a;
  int n = int((a).size());
  if (n == 1 && a[0] < 4) {
    cout << a[0] << endl;
    return 0;
  }
  int res = -1u / 2;
  for (int i = 0; i <= 2; ++i) {
    if (i) div<2>(a);
    double logA =
        n > 1 ? log(a[n - 1] * (double)RADIX + a[n - 2]) + LOG_RADIX * (n - 2)
              : log(a[n - 1]);
    logA = logA / LOG_3 - 1e-9;
    int powerOf3 = max(logA + 1, 0.0);
    double c = logA - int(logA);
    if (c < 0.9) {
      res = min(res, 3 * powerOf3 + i * 2);
      continue;
    }
    vi x = {1};
    for (int i = 30; i >= 0; --i) {
      sqr(x);
      if (powerOf3 & 1 << i) mul<3>(x);
    }
    if (cmp(x, a) < 0) ++powerOf3;
    res = min(res, 3 * powerOf3 + i * 2);
  }
  cout << res << endl;
  return 0;
}
