public class Euler664 {

    static final double kSqrt5 = 2.23606797749978969640917366873127623544;
    static final double kPhi = (1.0 + kSqrt5) / 2.0;
    static final double kLogPhi = Math.log(kPhi);
    static final double kTailDrop = 120.0;

    static double logTerm(long n, long d) {
        return (double) n * Math.log((double) d) - (double) d * kLogPhi;
    }

    static class Window {
        long left, right, peak;
        double peakLogTerm;
    }

    static Window buildWindow(long n) {
        Window out = new Window();

        long approx = 1;
        if (n > 0) {
            double center = (double) n / kLogPhi;
            approx = (long) center;
            if (approx == 0)
                approx = 1;
        }

        out.peak = approx;
        out.peakLogTerm = logTerm(n, out.peak);

        long scanLo = Math.max(1L, approx - 6);
        long scanHi = approx + 6;

        for (long d = scanLo; d <= scanHi; ++d) {
            double value = logTerm(n, d);
            if (value > out.peakLogTerm) {
                out.peakLogTerm = value;
                out.peak = d;
            }
        }

        out.left = out.peak;
        while (out.left > 1) {
            double nextVal = logTerm(n, out.left - 1);
            if (out.peakLogTerm - nextVal > kTailDrop)
                break;
            out.left--;
        }

        out.right = out.peak;
        while (true) {
            double nextVal = logTerm(n, out.right + 1);
            if (out.peakLogTerm - nextVal > kTailDrop)
                break;
            out.right++;
        }

        return out;
    }

    static long computeF(long n) {
        Window w = buildWindow(n);

        double total = 0.0;
        for (long d = w.left; d <= w.right; ++d) {
            total += Math.exp(logTerm(n, d) - w.peakLogTerm);
        }

        double logSeries = w.peakLogTerm + Math.log(total);
        double raw = logSeries / kLogPhi;

        long rounded = (long) Math.ceil(raw - 1e-15) + 3;
        return rounded;
    }

    public static String solve() {
        long ans = computeF(1234567L);
        return Long.toString(ans);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
