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;
template <typename T>
void dbg(T a) {}
template <typename T, typename... Arg>
void dbg(T a, Arg... arg) {}
const int maxn = (3e5) + 7;
const int maxk = 20;
const int inf = (1e9) + 7;
const long long LLinf = (1e18) + 7;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
using namespace std;
namespace FFT {
const int MAX = 1 << 21;
int N;
complex<double> omega[MAX];
complex<double> a1[MAX], a2[MAX];
complex<double> z1[MAX], z2[MAX];
void fft(complex<double> *a, complex<double> *z, int m = N) {
  if (m == 1) {
    z[0] = a[0];
  } else {
    int s = N / m;
    m /= 2;
    fft(a, z, m);
    fft(a + s, z + m, m);
    for (long long i = (long long)0; i < (long long)m; i++) {
      complex<double> c = omega[s * i] * z[m + i];
      z[m + i] = z[i] - c;
      z[i] += c;
    }
  }
}
void mult(long long *a, long long *b, long long *c, int len) {
  N = 2 * len;
  while (N & (N - 1)) ++N;
  assert(N <= MAX);
  for (long long i = (long long)0; i < (long long)N; i++) a1[i] = 0;
  for (long long i = (long long)0; i < (long long)N; i++) a2[i] = 0;
  for (long long i = (long long)0; i < (long long)len; i++) a1[i] = a[i];
  for (long long i = (long long)0; i < (long long)len; i++) a2[i] = b[i];
  for (long long i = (long long)0; i < (long long)N; i++)
    omega[i] = polar(1.0, 2 * acos(-1) / N * i);
  fft(a1, z1, N);
  fft(a2, z2, N);
  for (long long i = (long long)0; i < (long long)N; i++)
    omega[i] = complex<double>(1, 0) / omega[i];
  for (long long i = (long long)0; i < (long long)N; i++)
    a1[i] = z1[i] * z2[i] / complex<double>(N, 0);
  fft(a1, z1, N);
  for (long long i = (long long)0; i < (long long)2 * len; i++)
    c[i] = round(z1[i].real());
}
}  // namespace FFT
void mult_mod(long long *a, long long *b, long long *c, int len, int mod) {
  static long long a0[(1 << 19)], a1[(1 << 19)];
  static long long b0[(1 << 19)], b1[(1 << 19)];
  static long long c0[(1 << 19)], c1[(1 << 19)], c2[(1 << 19)];
  for (long long i = (long long)0; i < (long long)len; i++)
    a0[i] = a[i] & 0xFFFF;
  for (long long i = (long long)0; i < (long long)len; i++) a1[i] = a[i] >> 16;
  for (long long i = (long long)0; i < (long long)len; i++)
    b0[i] = b[i] & 0xFFFF;
  for (long long i = (long long)0; i < (long long)len; i++) b1[i] = b[i] >> 16;
  FFT::mult(a0, b0, c0, len);
  FFT::mult(a1, b1, c2, len);
  for (long long i = (long long)0; i < (long long)len; i++) a0[i] += a1[i];
  for (long long i = (long long)0; i < (long long)len; i++) b0[i] += b1[i];
  FFT::mult(a0, b0, c1, len);
  for (long long i = (long long)0; i < (long long)2 * len; i++)
    c1[i] -= c0[i] + c2[i];
  for (long long i = (long long)0; i < (long long)2 * len; i++) c1[i] %= mod;
  for (long long i = (long long)0; i < (long long)2 * len; i++) c2[i] %= mod;
  for (long long i = (long long)0; i < (long long)2 * len; i++)
    c[i] = (c0[i] + (c1[i] << 16) + (c2[i] << 32)) % mod;
}
void tra(int *from, int *to, bool rev) {
  if (to - from == 1) return;
  int *mid = from + (to - from) / 2;
  tra(from, mid, rev);
  tra(mid, to, rev);
  for (int i = 0; i < mid - from; i++) {
    int mnoz = 1;
    if (rev) mnoz = -1;
    *(mid + i) += mnoz * (*(from + i));
  }
}
vector<long long> trzy[maxn];
void form(vector<long long> &a) {
  for (int i = 0; i < ((int)(a).size()); i++) {
    if (a[i] >= 10000 && i + 1 == ((int)(a).size())) a.push_back(0);
    if (a[i] >= 10000) a[i + 1] += a[i] / 10000;
    a[i] %= 10000;
  }
  while (a.back() == 0) a.pop_back();
}
vector<long long> pot(int ile) {
  vector<long long> cur = {1}, xd = {0};
  for (long long i = 0; i < 60; i++) {
    if (ile & (1LL << i)) {
      xd.resize(2 * max(((int)(cur).size()), ((int)(trzy[i]).size())));
      cur.resize(max(((int)(cur).size()), ((int)(trzy[i]).size())));
      trzy[i].resize(max(((int)(cur).size()), ((int)(trzy[i]).size())));
      for (auto &s : xd) s = 0;
      FFT::mult(&cur[0], &trzy[i][0], &xd[0],
                max(((int)(cur).size()), ((int)(trzy[i]).size())));
      cur = xd;
      form(cur);
      form(trzy[i]);
    }
  }
  form(cur);
  return cur;
}
vector<long long> cur;
bool mniej(vector<long long> &a, vector<long long> &b) {
  if (((int)(a).size()) != ((int)(b).size()))
    return ((int)(a).size()) < ((int)(b).size());
  for (int i = ((int)(a).size()) - 1; i >= 0; i--)
    if (a[i] != b[i]) return a[i] < b[i];
  return 0;
}
void razy(vector<long long> &a, int x) {
  for (auto &s : a) s *= x;
  form(a);
}
vector<long long> xdxd;
long long ile(vector<long long> &a, long long xd) {
  xdxd = a;
  xd *= 3;
  int ile = 0;
  while (mniej(xdxd, cur)) {
    razy(xdxd, 2);
    ile++;
    if (ile > 2) return LLinf;
    xd += 2;
  }
  return xd;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  trzy[0].push_back(3);
  for (int i = 1; i < 100; i++) {
    while (((int)(trzy[i]).size()) < 2 * ((int)(trzy[i - 1]).size()))
      trzy[i].push_back(0);
    FFT::mult(&trzy[i - 1][0], &trzy[i - 1][0], &trzy[i][0],
              ((int)(trzy[i - 1]).size()));
    form(trzy[i]);
    if (((int)(trzy[i]).size()) > maxn) break;
  }
  string s;
  cin >> s;
  if (((int)(s).size()) == 1 && s[0] == '1') {
    cout << 1;
    return 0;
  }
  reverse(s.begin(), s.end());
  for (int i = 0; i < ((int)(s).size()); i += 4) {
    int xd = 0;
    for (int j = i + 3; j >= i; j--)
      if (((int)(s).size()) > j) xd = xd * 10 + s[j] - '0';
    cur.push_back(xd);
  }
  int wsk = (log(10) * ((int)(cur).size()) * 4 - 4) / log(3);
  wsk = max(0, wsk - 6);
  auto xd = pot(wsk);
  long long res = LLinf;
  while (mniej(xd, cur)) {
    res = min(res, ile(xd, wsk));
    wsk++;
    razy(xd, 3);
    form(xd);
  }
  res = min(res, ile(xd, wsk));
  cout << res;
  return 0;
}
