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 JAVA):

Solution:
import java.io.*;
import java.util.*;

public class Test {

    static int readInt() {
        int ans = 0;
        boolean neg = false;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '-') {
                    start = true;
                    neg = true;
                    continue;
                } else if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return neg ? -ans : ans;
    }

    static long readLong() {
        long ans = 0;
        boolean neg = false;
        try {
            boolean start = false;
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '-') {
                    start = true;
                    neg = true;
                    continue;
                } else if (c >= '0' && c <= '9') {
                    start = true;
                    ans = ans * 10 + c - '0';
                } else if (start) break;
            }
        } catch (IOException e) {
        }
        return neg ? -ans : ans;
    }

    static String readLine() {
        StringBuilder b = new StringBuilder();
        try {
            for (int c = 0; (c = System.in.read()) != -1; ) {
                if (c == '\n') {
                    break;
                } else {
                    b.append((char) (c));
                }
            }
        } catch (IOException e) {
        }
        return b.toString().trim();
    }

    static PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    static class FFT {
        int n;
        // Lookup tables.  Only need to recompute when size of FFT changes.
        double[] cos;
        double[] sin;

        public FFT(int n) {
            this.n = n;
            cos = new double[n / 2];
            sin = new double[n / 2];
        }

        /***************************************************************
         * fft.c
         * Douglas L. Jones
         * University of Illinois at Urbana-Champaign
         * January 19, 1992
         * http://cnx.rice.edu/content/m12016/latest/
         *
         *   fft: in-place radix-2 DIT DFT of a complex input
         *
         *   input:
         * n: length of FFT: must be a power of two
         * m: n = 2**m
         *   input/output
         * x: double array of length n with real part of data
         * y: double array of length n with imag part of data
         *
         *   Permission to copy and use this program is granted
         *   as long as this header is included.
         ****************************************************************/
        void fft(double[] x, double[] y, int n) {
            int i, j, k, n1, n2, a;
            double c, s, e, t1, t2;
            int m = Integer.numberOfTrailingZeros(Integer.highestOneBit(n));

            for (i = 0; i < n / 2; i++) {
                cos[i] = Math.cos(-2 * Math.PI * i / n);
                sin[i] = Math.sin(-2 * Math.PI * i / n);
            }

            // Bit-reverse
            j = 0;
            n2 = n / 2;
            for (i = 1; i < n - 1; i++) {
                n1 = n2;
                while (j >= n1) {
                    j = j - n1;
                    n1 = n1 / 2;
                }
                j = j + n1;

                if (i < j) {
                    t1 = x[i];
                    x[i] = x[j];
                    x[j] = t1;
                    t1 = y[i];
                    y[i] = y[j];
                    y[j] = t1;
                }
            }

            // FFT
            n1 = 0;
            n2 = 1;

            for (i = 0; i < m; i++) {
                n1 = n2;
                n2 = n2 + n2;
                a = 0;

                for (j = 0; j < n1; j++) {
                    c = cos[a];
                    s = sin[a];
                    a += 1 << (m - i - 1);

                    for (k = j; k < n; k = k + n2) {
                        t1 = c * x[k + n1] - s * y[k + n1];
                        t2 = s * x[k + n1] + c * y[k + n1];
                        x[k + n1] = x[k] - t1;
                        y[k + n1] = y[k] - t2;
                        x[k] = x[k] + t1;
                        y[k] = y[k] + t2;
                    }
                }
            }
        }

        void ifft(double[] x, double[] y, int n) {
            // take conjugate
            for (int i = 0; i < n; i++) y[i] = -y[i];
            // compute forward FFT
            fft(x, y, n);
            // take conjugate again
            for (int i = 0; i < n; i++) y[i] = -y[i];

            // divide by n
            for (int i = 0; i < n; i++) {
                x[i] /= n;
                y[i] /= n;
            }
        }
    }

    double[] a, ai, b;
    double[] d;
    int N;
    FFT f;
    final int P = 2;
    int base = (int)Math.pow(10, P);

    void square(double[] a, double[] ai, int n) {
        for (int i = 0; i < n; i++) {
            double re = a[i]*a[i] - ai[i]*ai[i];
            double im = a[i]*ai[i]*2;
            a[i] = re;
            ai[i] = im;
        }
    }

    int mul(double[] a, int m, int n) {
        double c = 0;
        int last = 0;
        for (int i = 0; i < n; i++) {
            int v = (int) (Math.round(a[i]*m + c));
            a[i] = v % base;
            c = v / base;
            if (a[i] != 0) last = i;
        }
        if (c != 0) a[n] = c;
        return (c != 0 || last >= n/2) ? n*2 : n;
    }

    int norm(double[] a, double[] ai, int n) {
        if (ai != null) Arrays.fill(ai, 0, n, 0);
        return mul(a, 1, n);
    }

    void pow(double[] a, int e) {
        Arrays.fill(a, 0);
        Arrays.fill(ai, 0);
        a[0] = 1;
        int n = 2;
        for (int i = Integer.highestOneBit(e); i > 0; i >>>= 1) {
            f.fft(a, ai, n);
            square(a, ai, n);
            f.ifft(a, ai, n);
            n = norm(a, ai, n);
            if ((e & i) != 0) n = mul(a, 3, n);
        }
    }

    int cmp(double[] a, double[] b) {
        for (int i = a.length - 1; i >= 0; i--)
            if (a[i] != b[i]) return (int) Math.round(a[i] - b[i]);
        return 0;
    }

    void start() {
        char[] s = readLine().toCharArray();
        int n = s.length;
        while (s[n-1] < '0' || s[n-1] > '9') n--;
        for (int i = 0; i < n; i++) s[i] -= '0';
        if (n == 1 && s[0] == 1) {
            writer.println(1);
            return;
        }
        N = Integer.highestOneBit((n + P - 1) / P) << 2;
        f = new FFT(N);
        a = new double[N];
        ai = new double[N];
        b = new double[N];
        d = new double[N];
        for (int i = 0; i < n; i += P) {
            int v = 1, r = 0;
            for (int j = n - 1 - i, k = 0; j >= 0 && k < P; j--, k++) {
                r += v * s[j];
                v *= 10;
            }
            d[i / P] = r;
        }
        // 3^p = 10^(n-1);
        int p3 = (int)Math.floor((n-1)*Math.log(10)/Math.log(3));
        pow(a, p3);
        for (int i = 0; i < 5; i++) {
            if (cmp(a, d) >= 0) break;
            p3++;
            mul(a, 3, a.length);
        }
        if (cmp(a, d) == 0) {
            writer.println(p3 * 3);
            return;
        }
        int best = p3 * 3;
        if (p3 >= 1) {
            mul(d, 3, a.length);
            mul(a, 2, a.length);
            if (cmp(a, d) >= 0) {
                best = Math.min(best, (p3 - 1) * 3 + 2);
            }
            mul(d, 3, a.length);
            mul(a, 2, a.length);
            if (cmp(a, d) >= 0) {
                best = Math.min(best, (p3 - 2)*3 +4);
            }
        } else {
            switch ((int) d[0]) {
                case 2:
                    best = 2;
                    break;
                case 3:
                    best = 3;
                    break;
                case 4:
                    best = 4;
                    break;
                case 5:
                case 6:
                    best = 5;
                    break;
                case 7:
                case 8:
                    best = 6;
                    break;
            }
        }

        writer.println(best);
    }

    public static void main(String[] args) {
        Test te = new Test();
        te.start();
        writer.flush();
    }
}