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>
#pragma GCC optimize(3)
#pragma GCC optimize("-Ofast")
using namespace std;
const int Inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3fll;
const int jt = 998244353, rg = 3;
int inline ksmii(int a, int b) {
  if (!b) return 1;
  int x = ksmii(a, b >> 1);
  x = 1ll * x * x % jt;
  if (b & 1) x = 1ll * x * a % jt;
  return x;
}
void inline fft(vector<int> &a, int inv) {
  int lg = 0, n = ((int)(a).size());
  vector<int> ho(n, 0);
  while ((1 << lg) < n) ++lg;
  for (int i = 0; i < (n); ++i) {
    ho[i] = (ho[i >> 1] >> 1) | ((i & 1) << (lg - 1));
    if (i < ho[i]) swap(a[i], a[ho[i]]);
  }
  for (int i = (1); (i) > 0 ? i <= (n - 1) : i >= (n - 1); i += (i)) {
    int omega = ksmii(rg, (jt - 1) / (i << 1));
    for (int j = (0); (i << 1) > 0 ? j <= (n - 1) : j >= (n - 1);
         j += (i << 1)) {
      int omg = 1;
      for (int k = 0; k < (i); ++k) {
        int tmp = 1ll * omg * a[j + k + i] % jt;
        a[j + k + i] = (a[j + k] + jt - tmp) % jt;
        a[j + k] = (a[j + k] + tmp) % jt;
        omg = 1ll * omg * omega % jt;
      }
    }
  }
  if (!~inv) {
    reverse(a.begin() + 1, a.end());
    int fn = ksmii(n, jt - 2);
    for (int i = 0; i < (n); ++i) a[i] = 1ll * a[i] * fn % jt;
  }
}
char tmp[1 << 21];
struct Bignum : vector<int> {
  Bignum() {}
  Bignum(int x) {
    while (x) {
      push_back(x % 10);
      x /= 10;
    }
  }
  bool inline operator<(const Bignum &b) const {
    if (((int)size()) != ((int)(b).size()))
      return ((int)size()) < ((int)(b).size());
    for (int i = (((int)size()) - 1); (-1) > 0 ? i <= (0) : i >= (0); i += (-1))
      if (at(i) != b[i]) return at(i) < b[i];
    return 0;
  }
  bool inline operator>(const Bignum &b) const {
    if (((int)size()) != ((int)(b).size()))
      return ((int)size()) > ((int)(b).size());
    for (int i = (((int)size()) - 1); (-1) > 0 ? i <= (0) : i >= (0); i += (-1))
      if (at(i) != b[i]) return at(i) > b[i];
    return 0;
  }
  bool inline operator==(const Bignum &b) const {
    if (((int)size()) != ((int)(b).size())) return 0;
    for (int i = (((int)size()) - 1); (-1) > 0 ? i <= (0) : i >= (0); i += (-1))
      if (at(i) != b[i]) return 0;
    return 1;
  }
  bool inline operator>=(const Bignum &b) const { return !(*this < b); }
  bool inline operator<=(const Bignum &b) const { return !(*this > b); }
  Bignum inline &operator*=(int x) {
    for (int i = 0; i < (((int)size())); ++i) at(i) *= x;
    for (int i = 0; i < (((int)size())); ++i) {
      if (at(i) >= 10 && i == ((int)size()) - 1) push_back(0);
      if (at(i) >= 10) at(i + 1) += at(i) / 10;
      at(i) %= 10;
    }
    return *this;
  }
  Bignum inline &operator*=(const Bignum &b) {
    if (((int)size()) + ((int)(b).size()) <= 512) {
      Bignum res;
      res.resize(((int)size()) + ((int)(b).size()) - 1);
      for (int i = 0; i < (((int)size())); ++i)
        for (int j = 0; j < (((int)(b).size())); ++j)
          res[i + j] += at(i) * b[j];
      for (int i = 0; i < (((int)(res).size())); ++i) {
        if (res[i] >= 10 && i == ((int)(res).size()) - 1) res.push_back(0);
        if (res[i] >= 10) res[i + 1] += res[i] / 10;
        res[i] %= 10;
      }
      return *this = res;
    }
    vector<int> A, B;
    for (int i = 0; i < (((int)size())); ++i) A.push_back(at(i));
    for (int i = 0; i < (((int)(b).size())); ++i) B.push_back(b[i]);
    int siz = 1, as = ((int)size()) + ((int)(b).size()) - 1;
    while (siz <= as) siz <<= 1;
    A.resize(siz);
    B.resize(siz);
    fft(A, 1);
    fft(B, 1);
    for (int i = 0; i < (siz); ++i) A[i] = 1ll * A[i] * B[i] % jt;
    fft(A, -1);
    resize(siz);
    for (int i = 0; i < (siz); ++i) at(i) = A[i];
    for (int i = 0; i < (((int)size())); ++i) {
      if (at(i) >= 10 && i == ((int)size()) - 1) push_back(0);
      if (at(i) >= 10) at(i + 1) += at(i) / 10;
      at(i) %= 10;
    }
    while (((int)size()) && !back()) pop_back();
    return *this;
  }
  Bignum inline &sqr() {
    vector<int> A;
    for (int i = 0; i < (((int)size())); ++i) A.push_back(at(i));
    int siz = 1, as = ((int)size()) + ((int)size()) - 1;
    while (siz <= as) siz <<= 1;
    A.resize(siz);
    fft(A, 1);
    for (int i = 0; i < (siz); ++i) A[i] = 1ll * A[i] * A[i] % jt;
    fft(A, -1);
    resize(siz);
    for (int i = 0; i < (siz); ++i) at(i) = A[i];
    for (int i = 0; i < (((int)size())); ++i) {
      if (at(i) >= 10 && i == ((int)size()) - 1) push_back(0);
      if (at(i) >= 10) at(i + 1) += at(i) / 10;
      at(i) %= 10;
    }
    while (((int)size()) && !back()) pop_back();
    return *this;
  }
  Bignum inline &operator/=(int x) {
    for (int i = (((int)size()) - 1); (-1) > 0 ? i <= (0) : i >= (0);
         i += (-1)) {
      if (i) at(i - 1) += at(i) % x * 10;
      at(i) /= x;
    }
    while (((int)size()) && !back()) pop_back();
    return *this;
  }
  void inline write() {
    if (!((int)size())) putchar('0');
    for (int i = (((int)size()) - 1); (-1) > 0 ? i <= (0) : i >= (0); i += (-1))
      putchar(at(i) + '0');
  }
  void inline read() {
    scanf("%s", tmp);
    int m = strlen(tmp);
    resize(m);
    for (int i = (m - 1); (-1) > 0 ? i <= (0) : i >= (0); i += (-1))
      at(m - 1 - i) = tmp[i] - '0';
    while (((int)size()) && !back()) pop_back();
  }
};
Bignum res;
void inline qp(int a, int b) {
  if (!b) return void(res = 1);
  qp(a, b >> 1);
  res.sqr();
  if (b & 1) res *= a;
}
Bignum n, m;
int main() {
  n.read();
  if (n <= 4) return n.write(), 0;
  int lg = ((int)(n).size()) / log10(3) - 1;
  int mii = lg;
  qp(3, lg);
  m = res;
  while (m < n) ++mii, m *= 3;
  n *= 3;
  int ans = mii * 3;
  for (int s2 = 1; s2 <= (2); ++s2) {
    m *= 2;
    while (m >= n) --mii, m /= 3;
    ans = min(ans, mii * 3 + s2 * 2);
  }
  printf("%d\n", ans);
  return 0;
}
