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 maxn = 2e6 + 20, maxm = 2e6 + 10;
vector<int> ans, ss, x;
const double pi = acos(-1);
struct cn {
  double x, y;
  cn(double x = 0, double y = 0) : x(x), y(y) {}
} a[maxn], b[maxn];
cn operator+(const cn &a, const cn &b) { return cn(a.x + b.x, a.y + b.y); }
cn operator-(const cn &a, const cn &b) { return cn(a.x - b.x, a.y - b.y); }
cn operator*(const cn &a, const cn &b) {
  return cn(a.x * b.x - a.y * b.y, a.x * b.y + a.y * b.x);
}
void fft(cn a[], int n, int l, int f) {
  int rev[n + 5];
  rev[0] = 0;
  for (int i = 1; i < n; i++) {
    rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << l - 1);
    if (i < rev[i]) swap(a[i], a[rev[i]]);
  }
  for (int i = 1; i < n; i <<= 1) {
    cn wi(cos(pi / i), f * sin(pi / i));
    for (int j = 0; j < n; j += i * 2) {
      cn w(1, 0);
      for (int k = 0; k < i; k++) {
        cn x = a[j + k], y = w * a[j + k + i];
        a[j + k] = x + y;
        a[j + k + i] = x - y;
        w = w * wi;
      }
    }
  }
  if (f == -1)
    for (int i = 0; i < n; i++) {
      a[i].x /= n;
      a[i].y /= n;
    }
}
vector<int> mul(vector<int> ans, vector<int> x) {
  int len = ans.size() + x.size();
  int l = 0, N = 1;
  while (N < len - 1) N <<= 1, l++;
  for (int i = 0; i < ans.size(); i++) a[i].x = ans[i];
  for (int i = 0; i < x.size(); i++) b[i].x = x[i];
  fft(a, N, l, 1);
  fft(b, N, l, 1);
  for (int i = 0; i < N; i++) a[i] = a[i] * b[i];
  fft(a, N, l, -1);
  vector<int> res(len - 1);
  for (int i = 0; i < len - 1; i++) res[i] = (int)(a[i].x + 0.5);
  for (int i = 0; i < N; i++) a[i] = b[i] = {0, 0};
  return res;
}
const int mod = 100;
void recal(vector<int> &x) {
  int now = 0, len = x.size();
  for (int i = 0; i < len || now; i++) {
    if (i >= len) x.push_back(0);
    long long cur = x[i];
    x[i] = (cur + now) % mod;
    now = (cur + now) / mod;
  }
}
void quick_pow(int k) {
  x.push_back(3);
  ans.push_back(1);
  while (k) {
    if (k & 1) ans = mul(ans, x), recal(ans);
    x = mul(x, x), recal(x);
    k >>= 1;
  }
}
void rcal() {
  for (int i = 0; i < ans.size(); i++) ans[i] *= 3;
  recal(ans);
}
char s[maxn];
bool calc(int x) {
  vector<int> now;
  for (int i = 0; i < ans.size(); i++) now.push_back(ans[i] * x);
  recal(now);
  int la = now.size(), lb = ss.size();
  if (la < lb) return 0;
  if (la > lb) return 1;
  for (int i = la - 1; ~i; i--) {
    if (now[i] > ss[i]) return 1;
    if (now[i] < ss[i]) return 0;
  }
  return 1;
}
int as[10] = {0, 1, 2, 3, 4, 5, 5, 6, 6, 6};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  scanf("%s", s);
  int l = strlen(s);
  reverse(s, s + l);
  if (l == 1) return cout << as[s[0] - '0'] << '\n', 0;
  for (int i = 0; i < l; i += 2) {
    int now = s[i] - '0';
    if (i < l - 1) now += (s[i + 1] - '0') * 10;
    ss.push_back(now);
  }
  int k = (l - 1) * (double)(log(10) / log(3));
  k--;
  int res = 3 * k;
  quick_pow(k);
  for (;; res += 3, rcal()) {
    if (calc(2)) {
      res += 2;
      break;
    } else if (calc(3)) {
      res += 3;
      break;
    } else if (calc(4)) {
      res += 4;
      break;
    }
  }
  cout << res << '\n';
}