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;
const int N = 3e6 + 10;
const int mod = 100;
const long double pi = acos(-1);
int n, siz, bas, ans;
int rev[N], t[N];
char s[N];
vector<int> a, b;
struct E {
  long double r, i;
  E() {}
  E(long double rx, long double ix) {
    r = rx;
    i = ix;
  }
  E operator+(E const &A) const { return E(r + A.r, i + A.i); }
  E operator-(E const &A) const { return E(r - A.r, i - A.i); }
  E operator*(E const &A) const {
    return E(r * A.r - i * A.i, r * A.i + i * A.r);
  }
} x1[N], x2[N];
void fft(E *a, int n, int f) {
  for (int i = 0; i < n; ++i)
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  for (int i = 1; i < n; i <<= 1) {
    E wn = E(cos(pi / i), f * sin(pi / i));
    for (int j = 0; j < n; j += (i << 1)) {
      E w = E(1, 0);
      for (int k = 0; k < i; ++k, w = w * wn) {
        E x = a[j + k], y = w * a[i + j + k];
        a[j + k] = x + y;
        a[i + j + k] = x - y;
      }
    }
  }
  if (f == -1)
    for (int i = 0; i < n; ++i) a[i].r /= (long double)n;
}
void mul(vector<int> a, vector<int> b, vector<int> &c) {
  int L = 0, m = 1, s1 = (int)a.size(), s2 = (int)b.size();
  for (; m <= s1 + s2 - 1; m <<= 1, ++L)
    ;
  for (int i = 1; i < m; ++i)
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (L - 1));
  for (int i = 0; i < s1; ++i) x1[i] = E(a[i], 0);
  for (int i = s1; i < m; ++i) x1[i] = E(0, 0);
  for (int i = 0; i < s2; ++i) x2[i] = E(b[i], 0);
  for (int i = s2; i < m; ++i) x2[i] = E(0, 0);
  fft(x1, m, 1);
  fft(x2, m, 1);
  for (int i = 0; i < m; ++i) x1[i] = x1[i] * x2[i];
  fft(x1, m, -1);
  c.clear();
  for (int i = 0; i < s1 + s2 - 1; ++i) c.push_back((int)(x1[i].r + 0.5));
}
void update(vector<int> &a) {
  int p = 0, sz = (int)a.size();
  for (int i = 0; i < sz || p; ++i) {
    if (i >= sz) a.push_back(0);
    long long cnt = a[i] + p;
    a[i] = cnt % mod;
    p = cnt / mod;
  }
}
void mul3() {
  for (int i = 0; i < (int)b.size(); ++i) b[i] *= 3;
  update(b);
}
int cmp(vector<int> a) {
  int sz = (int)a.size();
  if (sz < siz) return 0;
  if (sz > siz) return 1;
  for (int i = sz - 1; ~i; --i) {
    if (a[i] < t[i]) return 0;
    if (a[i] > t[i]) return 1;
  }
  return 1;
}
void solve1() {
  int x = s[0] - '0';
  if (x <= 5)
    printf("%d\n", x);
  else if (x == 6)
    puts("5");
  else
    puts("6");
}
int check(int x) {
  vector<int> c;
  for (int i = 0; i < (int)b.size(); ++i) c.push_back(b[i] * x);
  update(c);
  return cmp(c);
}
int main() {
  scanf("%s", s);
  int len = strlen(s);
  if (len < 2) {
    solve1();
    return 0;
  }
  reverse(s, s + len);
  for (int i = 0; i < len; i += 2) {
    int x = s[i] - '0';
    if (i + 1 < len) x = x + (s[i + 1] - '0') * 10;
    t[siz++] = x;
  }
  bas = (len - 1) * (long double)(log(10) / log(3));
  --bas;
  ans += bas * 3;
  a.push_back(3);
  b.push_back(1);
  for (; bas; bas >>= 1) {
    if (bas & 1) mul(b, a, b), update(b);
    mul(a, a, a), update(a);
  }
  for (;; ans += 3, mul3()) {
    for (int i = 2; i <= 4; ++i)
      if (check(i)) {
        printf("%d\n", ans + i);
        return 0;
      }
  }
  return 0;
}