#include <bits/stdc++.h>
using namespace std;
char s[(1 << 21)];
int is_less(const vector<int> &a, const vector<int> &b) {
  if (a.size() != b.size()) return a.size() < b.size();
  for (int i = a.size(); i--;)
    if (a[i] != b[i]) return a[i] < b[i];
  return 1;
}
void mul(vector<int> &a, const int &v) {
  int c = 0;
  for (int i = 0; i < a.size(); i++) {
    c = c + a[i] * v;
    a[i] = c % 10;
    c /= 10;
  }
  if (c) a.push_back(c);
}
const int MOD = 998244353;
int power(int a, int b, int c, int ans = 1) {
  for (; b; b >>= 1, a = (long long)a * a % MOD)
    if (b & 1) ans = (long long)ans * a % MOD;
  return ans;
}
namespace fft {
const int root = 31;
const int root_1 = power(root, MOD - 2, MOD);
int mPow(int a, int x) { return power(a, x, MOD); }
void fft(vector<int> &a, bool invert) {
  int n = a.size();
  int PW = mPow(invert ? root_1 : root, (MOD - 1) / n);
  for (int m = n, h; h = m / 2, m >= 2; PW = 1LL * PW * PW % MOD, m = h) {
    for (int i = 0, w = 1; i < h; ++i, w = 1LL * w * PW % MOD)
      for (int j = i; j < n; j += m) {
        int k = j + h, x = (a[j] - a[k] + MOD) % MOD;
        a[j] += a[k];
        a[j] %= MOD;
        a[k] = 1LL * w * x % MOD;
      }
  }
  for (int i = 0, j = 1; j < n - 1; ++j) {
    for (int k = n / 2; k > (i ^= k); k /= 2)
      ;
    if (j < i) swap(a[i], a[j]);
  }
  if (invert) {
    int rev = mPow(n, MOD - 2);
    for (int i = 0; i < n; ++i) a[i] = 1LL * a[i] * rev % MOD;
  }
}
vector<int> multiply(const vector<int> &a) {
  int n = 1, mx = a.size() + a.size() - 1;
  while (n < mx) n <<= 1;
  if (mx < 256) {
    vector<int> c(mx);
    for (int i = 0; i < a.size(); i++)
      for (int j = 0; j < a.size(); j++) {
        c[i + j] = (c[i + j] + (long long)a[i] * a[j]) % MOD;
      }
    int mid = 0;
    for (int i = 0; i < mx; i++) {
      mid += c[i];
      c[i] = mid % 10;
      mid /= 10;
    }
    while (mid) c.emplace_back(mid % 10), mid /= 10;
    return c;
  }
  vector<int> na = a;
  na.resize(n);
  fft(na, false);
  for (int i = 0; i < n; ++i) na[i] = 1LL * na[i] * na[i] % MOD;
  fft(na, true);
  na.resize(mx);
  int mid = 0;
  for (int i = 0; i < mx; i++) {
    mid += na[i];
    na[i] = mid % 10;
    mid /= 10;
  }
  while (mid) na.emplace_back(mid % 10), mid /= 10;
  return na;
}
};  // namespace fft
vector<int> calc(int n) {
  if (n == 1) return vector<int>(1, 3);
  vector<int> a = calc(n >> 1);
  a = fft::multiply(a);
  if (n & 1) mul(a, 3);
  return a;
}
int main() {
  gets(s);
  int len = strlen(s);
  if (len == 1) {
    int n = atoi(s);
    if (n < 6) cout << n << endl;
    if (n == 6) puts("5");
    if (n >= 7) puts("6");
    return 0;
  }
  int m = (int)((len - 1) * log(10) / log(3));
  vector<int> a(len);
  for (int i = 0; i < len; i++) a[len - 1 - i] = s[i] - '0';
  vector<int> b = calc(m - 1), c = b;
  mul(b, 3);
  vector<int> d = b;
  mul(d, 2);
  mul(c, 4);
  int ans = m * 3;
  while (true) {
    if (is_less(a, b)) break;
    mul(b, 3);
    ans++;
    if (is_less(a, c)) break;
    mul(c, 3);
    ans++;
    if (is_less(a, d)) break;
    mul(d, 3);
    ans++;
  }
  cout << ans << endl;
  return 0;
}

### Prompt

Develop a solution in Cpp to the problem described below:

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

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
char s[(1 << 21)];
int is_less(const vector<int> &a, const vector<int> &b) {
  if (a.size() != b.size()) return a.size() < b.size();
  for (int i = a.size(); i--;)
    if (a[i] != b[i]) return a[i] < b[i];
  return 1;
}
void mul(vector<int> &a, const int &v) {
  int c = 0;
  for (int i = 0; i < a.size(); i++) {
    c = c + a[i] * v;
    a[i] = c % 10;
    c /= 10;
  }
  if (c) a.push_back(c);
}
const int MOD = 998244353;
int power(int a, int b, int c, int ans = 1) {
  for (; b; b >>= 1, a = (long long)a * a % MOD)
    if (b & 1) ans = (long long)ans * a % MOD;
  return ans;
}
namespace fft {
const int root = 31;
const int root_1 = power(root, MOD - 2, MOD);
int mPow(int a, int x) { return power(a, x, MOD); }
void fft(vector<int> &a, bool invert) {
  int n = a.size();
  int PW = mPow(invert ? root_1 : root, (MOD - 1) / n);
  for (int m = n, h; h = m / 2, m >= 2; PW = 1LL * PW * PW % MOD, m = h) {
    for (int i = 0, w = 1; i < h; ++i, w = 1LL * w * PW % MOD)
      for (int j = i; j < n; j += m) {
        int k = j + h, x = (a[j] - a[k] + MOD) % MOD;
        a[j] += a[k];
        a[j] %= MOD;
        a[k] = 1LL * w * x % MOD;
      }
  }
  for (int i = 0, j = 1; j < n - 1; ++j) {
    for (int k = n / 2; k > (i ^= k); k /= 2)
      ;
    if (j < i) swap(a[i], a[j]);
  }
  if (invert) {
    int rev = mPow(n, MOD - 2);
    for (int i = 0; i < n; ++i) a[i] = 1LL * a[i] * rev % MOD;
  }
}
vector<int> multiply(const vector<int> &a) {
  int n = 1, mx = a.size() + a.size() - 1;
  while (n < mx) n <<= 1;
  if (mx < 256) {
    vector<int> c(mx);
    for (int i = 0; i < a.size(); i++)
      for (int j = 0; j < a.size(); j++) {
        c[i + j] = (c[i + j] + (long long)a[i] * a[j]) % MOD;
      }
    int mid = 0;
    for (int i = 0; i < mx; i++) {
      mid += c[i];
      c[i] = mid % 10;
      mid /= 10;
    }
    while (mid) c.emplace_back(mid % 10), mid /= 10;
    return c;
  }
  vector<int> na = a;
  na.resize(n);
  fft(na, false);
  for (int i = 0; i < n; ++i) na[i] = 1LL * na[i] * na[i] % MOD;
  fft(na, true);
  na.resize(mx);
  int mid = 0;
  for (int i = 0; i < mx; i++) {
    mid += na[i];
    na[i] = mid % 10;
    mid /= 10;
  }
  while (mid) na.emplace_back(mid % 10), mid /= 10;
  return na;
}
};  // namespace fft
vector<int> calc(int n) {
  if (n == 1) return vector<int>(1, 3);
  vector<int> a = calc(n >> 1);
  a = fft::multiply(a);
  if (n & 1) mul(a, 3);
  return a;
}
int main() {
  gets(s);
  int len = strlen(s);
  if (len == 1) {
    int n = atoi(s);
    if (n < 6) cout << n << endl;
    if (n == 6) puts("5");
    if (n >= 7) puts("6");
    return 0;
  }
  int m = (int)((len - 1) * log(10) / log(3));
  vector<int> a(len);
  for (int i = 0; i < len; i++) a[len - 1 - i] = s[i] - '0';
  vector<int> b = calc(m - 1), c = b;
  mul(b, 3);
  vector<int> d = b;
  mul(d, 2);
  mul(c, 4);
  int ans = m * 3;
  while (true) {
    if (is_less(a, b)) break;
    mul(b, 3);
    ans++;
    if (is_less(a, c)) break;
    mul(c, 3);
    ans++;
    if (is_less(a, d)) break;
    mul(d, 3);
    ans++;
  }
  cout << ans << endl;
  return 0;
}

```