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;
using cd = complex<double>;
const double PI = acos(-1.0);
const long long B = 1000;
const long long K = 3;
long long rev[6000010], cur_len = 0;
cd W[6000010];
void reverse(long long n) {
  for (long long i = 0; i < n; ++i) {
    rev[i] = rev[i >> 1] >> 1;
    if (i & 1) rev[i] ^= (n >> 1);
  }
}
void fft(vector<cd>& A, bool inv = 0) {
  long long n = A.size();
  if (cur_len != n) reverse(n), cur_len = n;
  for (long long i = 0; i < n; ++i) {
    if (i < rev[i]) swap(A[i], A[rev[i]]);
  }
  for (long long s = 1; s < n; s <<= 1) {
    double x = (inv ? -1 : 1) * PI / s;
    cd w(cos(x), sin(x));
    W[0] = cd(1, 0);
    for (long long i = 1; i < s; ++i) W[i] = W[i - 1] * w;
    for (long long i = 0; i < n; i += 2 * s) {
      for (long long j = 0; j < s; ++j) {
        cd u = A[i + j], v = A[i + j + s] * W[j];
        A[i + j] = u + v, A[i + j + s] = u - v;
      }
    }
  }
  if (inv)
    for (long long i = 0; i < n; ++i) A[i] /= (n << 1);
}
vector<long long> mul(vector<long long>& a, long long x);
vector<long long> mul(const vector<long long>& a) {
  vector<long long> b = a;
  long long n = 1;
  while (n < (long long)(a).size() + (long long)(b).size()) n <<= 1;
  vector<cd> A(n);
  for (long long i = 0; i < n; ++i) {
    double x = 0, y = 0;
    if (i < (long long)(a).size()) x = a[i];
    if (i < (long long)(b).size()) y = b[i];
    A[i] = cd(x, y);
  }
  fft(A);
  for (long long i = 0; i < n; ++i) A[i] = A[i] * A[i];
  fft(A, 1);
  vector<long long> ans, tmp(n);
  for (long long i = 0; i < n; ++i) tmp[i] = (long long)(A[i].imag() + 0.5);
  while ((long long)(tmp).size() > 1 and !tmp.back()) tmp.pop_back();
  ans = mul(tmp, 1);
  return ans;
}
vector<long long> get(string s) {
  vector<long long> now;
  for (long long i = (long long)(s).size() - 1; i >= 0; i -= K) {
    long long x = 0;
    for (long long j = max(0ll, i - (K - 1)); j <= i; ++j) {
      x = 10 * x + (s[j] - '0');
    }
    now.push_back(x);
  }
  return now;
}
vector<long long> mul(vector<long long>& a, long long x) {
  vector<long long> ans;
  long long car = 0;
  for (long long i = 0; i < (long long)(a).size(); ++i) {
    car += a[i] * x, ans.push_back(car % B), car /= B;
  }
  while (car) ans.push_back(car % B), car /= B;
  return ans;
}
vector<long long> pw3(long long k) {
  vector<long long> ans(1, 1);
  long long x = 0;
  while ((1 << x) <= k) ++x;
  for (long long i = x - 1; i >= 0; --i) {
    ans = mul(ans);
    if (k & (1 << i)) ans = mul(ans, 3);
  }
  return ans;
}
string tostring(vector<long long> v) {
  string ans;
  for (long long i = 0; i < (long long)(v).size(); ++i) {
    long long x = v[i];
    string now;
    while (x) now += (x % 10 + '0'), x /= 10;
    if (i)
      while ((long long)(now).size() < K) now += "0";
    reverse((now).begin(), (now).end());
    ans += now + " ";
  }
  return ans;
}
bool greatr(vector<long long>& a, vector<long long>& b) {
  if ((long long)(a).size() != (long long)(b).size())
    return (long long)(a).size() > (long long)(b).size();
  for (long long i = (long long)(a).size() - 1; i >= 0; --i) {
    if (a[i] == b[i]) continue;
    return a[i] > b[i];
  }
  return 1;
}
long long go(long long x) {
  if (x < 0) return 0;
  return (long long)(log(10.0) * x) / (long double)log(3.0);
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  string s;
  cin >> s;
  if (s == "1") {
    cout << 1;
    return 0;
  }
  long long n = go((long long)(s).size() - 1);
  vector<long long> three = pw3(n), N = get(s);
  long long ans = 1e18, ct = go(3);
  while (ct--) {
    vector<long long> now = three;
    for (long long i = 0; i < 3; ++i) {
      if (greatr(now, N)) {
        ans = min(ans, 3 * n + 2 * i);
      }
      now = mul(now, 2);
    }
    three = mul(three, 3);
    n++;
  }
  cout << ans;
  return 0;
}