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 double PI = 4 * atan(1);
const long long B = (long long)1000;
const int LOG = 19;
const int N = (1 << LOG);
const int NN = N + 5;
complex<double> w[NN];
int rev[NN];
void printVec(vector<long long> a) {
  for (long long x : a) 42;
  42;
}
void initFFT() {
  for (int i = 0; i < N; i++)
    w[i] = complex<double>(cos(2 * PI * i / N), sin(2 * PI * i / N));
  rev[0] = 0;
  for (int mask = 1; mask < N; mask++) {
    int k = 0;
    while (((mask >> k) & 1) == 0) k++;
    rev[mask] = rev[mask ^ (1 << k)] ^ (1 << (LOG - 1 - k));
  }
}
complex<double> F[2][NN];
void FFT(complex<double>* A, int k) {
  int L = 1 << k;
  for (int i = 0; i < L; i++) F[0][rev[i] >> (LOG - k)] = A[i];
  int t = 0, nt = 1;
  for (int lvl = 0; lvl < k; lvl++) {
    int len = 1 << lvl;
    for (int st = 0; st < L; st += (len << 1))
      for (int i = 0; i < len; i++) {
        complex<double> ad = F[t][st + len + i] * w[i << (LOG - 1 - lvl)];
        F[nt][st + i] = F[t][st + i] + ad;
        F[nt][st + len + i] = F[t][st + i] - ad;
      }
    swap(t, nt);
  }
  for (int i = 0; i < L; i++) A[i] = F[t][i];
}
complex<double> A[NN];
bool ls(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]) continue;
    return a[i] < b[i];
  }
  return false;
}
vector<long long> sqr(vector<long long> a) {
  int L = (int)a.size();
  int k = 0;
  while (L > (1 << k)) k++;
  k++;
  L = 1 << k;
  for (int i = 0; i < L; i++) A[i] = 0;
  for (int i = 0; i < (int)a.size(); i++) A[i] = a[i];
  FFT(A, k);
  for (int i = 0; i < L; i++) A[i] *= A[i];
  FFT(A, k);
  vector<long long> res;
  res.resize(L);
  for (int i = 0; i < L; i++) res[i] = (long long)(A[i].real() / L + 0.5);
  reverse(res.begin() + 1, res.end());
  long long d = 0;
  for (int i = 0; i < L; i++) {
    d += res[i];
    res[i] = d % B;
    d /= B;
  }
  while ((int)res.size() > 1 && res.back() == 0) res.pop_back();
  return res;
}
vector<long long> multBy(vector<long long> a, long long x) {
  long long d = 0;
  for (int i = 0; i < (int)a.size() || d; i++) {
    if (i >= (int)a.size()) a.push_back(0LL);
    d += a[i] * x;
    a[i] = d % B;
    d /= B;
  }
  return a;
}
vector<long long> pow3(int pw) {
  vector<long long> res;
  res.push_back(1LL);
  int k = 0;
  while (pw >= (1 << k)) k++;
  for (int i = k - 1; i >= 0; i--) {
    res = sqr(res);
    if ((pw >> i) & 1) res = multBy(res, 3);
  }
  return res;
}
char s[3 * NN];
vector<long long> c;
int ANS = (int)1e9;
int read() {
  scanf("%s", s);
  int L = strlen(s);
  for (int pos = L; pos > 0; pos -= 3) {
    long long x = 0;
    for (int i = pos - 3; i < pos; i++) {
      if (i < 0) continue;
      x = x * 10 + (long long)(s[i] - '0');
    }
    c.push_back(x);
  }
  return L;
}
int main() {
  initFFT();
  int pw = (int)(read() * log(10) / log(3)) - 6;
  pw = max(pw, 0);
  vector<long long> st = pow3(pw);
  for (int k = 0; k < 3; k++) {
    int curAns = pw * 3 + k * 2;
    vector<long long> cur = multBy(st, 1LL << k);
    while (ls(cur, c)) {
      curAns += 3;
      cur = multBy(cur, 3LL);
    }
    ANS = min(ANS, curAns);
  }
  ANS = max(ANS, 1);
  printf("%d\n", ANS);
  return 0;
}