John Doe has a list of all Fibonacci numbers modulo 1013. This list is infinite, it starts with numbers 0 and 1. Each number in the list, apart from the first two, is a sum of previous two modulo 1013. That is, John's list is made from the Fibonacci numbers' list by replacing each number there by the remainder when divided by 1013. John got interested in number f (0 ≤ f < 1013) and now wants to find its first occurrence in the list given above. Help John and find the number of the first occurence of number f in the list or otherwise state that number f does not occur in the list. The numeration in John's list starts from zero. There, the 0-th position is the number 0, the 1-st position is the number 1, the 2-nd position is the number 1, the 3-rd position is the number 2, the 4-th position is the number 3 and so on. Thus, the beginning of the list looks like this: 0, 1, 1, 2, 3, 5, 8, 13, 21, ...

The first line contains the single integer f (0 ≤ f < 1013) — the number, which position in the list we should find. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.

Print a single number — the number of the first occurrence of the given number in John's list. If this number doesn't occur in John's list, print -1.

using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;
            const long BMod = 10000000;

            public static long MulMod(long a, long b, long mod)
            {
                if (a == 0 || b == 0)
                    return 0;
                else if (long.MaxValue / b > a)
                    return (a * b) % mod;
                else
                {
                    long j0 = a / BMod;
                    long j1 = a % BMod;
                    long k0 = b / BMod;
                    long k1 = b % BMod;
                    long r = (((j0 * k1 + j1 * k0) % (mod / BMod)) * BMod + j1 * k1) % mod;
                    return r;
                }
            }

            public static Matrix MulMod(Matrix m1, Matrix m2, long mod)
            {
                Matrix result = new Matrix();
                result.A1 = (MulMod(m1.A1, m2.A1, mod) + MulMod(m1.A2, m2.A3, mod)) % mod;
                result.A2 = (MulMod(m1.A1, m2.A2, mod) + MulMod(m1.A2, m2.A4, mod)) % mod;
                result.A3 = (MulMod(m1.A3, m2.A1, mod) + MulMod(m1.A4, m2.A3, mod)) % mod;
                result.A4 = (MulMod(m1.A3, m2.A2, mod) + MulMod(m1.A4, m2.A4, mod)) % mod;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(long power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.MulMod(result, modLast, mod);
                    }

                    modLast = Matrix.MulMod(modLast, modLast, mod);
                    power >>= 1;
                }

                return result;
            }
        }

        struct Result
        {
            public long Index, Value;
            public int SIndex;
        }

        static void Main(string[] args)
        {
            long[] steps = new long[] { 60, 300, 1500, 15000, 150000, 1500000, 15000000, 150000000, 1500000000, 15000000000, 150000000000, 1500000000000, 15000000000000, 150000000000000, 1500000000000000, 15000000000000000 };
            long[] mods = new long[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000 };

            long n = Convert.ToInt64(Console.ReadLine());

            if (n == 1)
            {
                Console.WriteLine(1);
                return;
            }

            int index = 0;
            long modValue = n % mods[index];

            Queue<Result> queue = new Queue<Result>();
            long[] fs = new long[60]; fs[1] = 1;

            for (int i = 2; i < fs.Length; i++)
            {
                fs[i] = (fs[i - 1] + fs[i - 2]) % mods[index];
                if (fs[i] == modValue)
                    queue.Enqueue(new Result { Index = i, Value = fs[i], SIndex = index });
            }

            List<Result> result = new List<Result>();

            while (queue.Count > 0)
            {
                Result current = queue.Dequeue();

                if (current.Value == n && current.SIndex == 12)
                {
                    result.Add(current);
                    continue;
                }
                else if (current.SIndex > 12)
                    continue;

                for (int i = 0; i * steps[current.SIndex] < steps[current.SIndex + 1]; i++)
                {
                    long nIndex = i * steps[current.SIndex] + current.Index;
                    long value = Cal(nIndex, mods[current.SIndex + 1]);

                    if (value == n % mods[current.SIndex + 1])
                        queue.Enqueue(new Result { Index = nIndex, SIndex = current.SIndex + 1, Value = value });
                }
            }

            if (result.Count == 0)
                Console.WriteLine(-1);
            else
            {
                long sIndex = result.Select(x => x.Index).Min();
                Console.WriteLine(sIndex);
            }
        }

        static long Cal(long index, long mod)
        {
            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            Matrix power = Matrix.PowerMod(index, m, mod);
            return (long)power.A2;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;

            public static Matrix Mul(Matrix m1, Matrix m2)
            {
                Matrix result = new Matrix();
                result.A1 = m1.A1 * m2.A1 + m1.A2 * m2.A3;
                result.A2 = m1.A1 * m2.A2 + m1.A2 * m2.A4;
                result.A3 = m1.A3 * m2.A1 + m1.A4 * m2.A3;
                result.A4 = m1.A3 * m2.A2 + m1.A4 * m2.A4;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(long power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.Mul(result, modLast);

                        result.Mod(mod);
                    }

                    modLast = Matrix.Mul(modLast, modLast);
                    modLast.Mod(mod);
                    power >>= 1;
                }

                return result;
            }
        }

        struct Result
        {
            public long Index, Value;
            public int SIndex;
        }

        static void Main(string[] args)
        {
            long[] steps = new long[] { 60, 300, 1500, 15000, 150000, 1500000, 15000000, 150000000, 1500000000, 15000000000, 150000000000, 1500000000000, 15000000000000, 150000000000000, 1500000000000000, 15000000000000000 };
            long[] mods = new long[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 1000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000 };

            long n = Convert.ToInt64(Console.ReadLine());
            int index = 0;
            long modValue = n % mods[index];

            Queue<Result> queue = new Queue<Result>();
            long[] fs = new long[60]; fs[1] = 1;

            for (int i = 2; i < fs.Length; i++)
            {
                fs[i] = (fs[i - 1] + fs[i - 2]) % mods[index];
                if (fs[i] == modValue)
                    queue.Enqueue(new Result { Index = i, Value = fs[i], SIndex = index });
            }

            List<Result> result = new List<Result>();

            while (queue.Count > 0)
            {
                Result current = queue.Dequeue();

                if (current.Value == n && current.SIndex == 12)
                {
                    result.Add(current);
                    continue;
                }
                else if (current.SIndex > 12)
                    continue;

                for (int i = 0; i * steps[current.SIndex] < steps[current.SIndex + 1]; i++)
                {
                    long nIndex = i * steps[current.SIndex] + current.Index;
                    long value = Cal(nIndex, mods[current.SIndex + 1]);

                    if (value == n % mods[current.SIndex + 1])
                        queue.Enqueue(new Result { Index = nIndex, SIndex = current.SIndex + 1, Value = value });
                }
            }

            if (result.Count == 0)
                Console.WriteLine(-1);
            else
            {
                long sIndex = result.Select(x => x.Index).Min();
                Console.WriteLine(sIndex);
            }
        }

        static long Cal(long index, long mod)
        {
            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            Matrix power = Matrix.PowerMod(index, m, mod);
            return power.A2;
        }
    }
}

using System;
using System.Collections.Generic;
using System.Linq;

namespace CodeForces
{
    class Program
    {
        struct Matrix
        {
            public long A1, A2, A3, A4;
            const long BMod = 10000000;

            public static long MulMod(long a, long b, long mod)
            {
                if (a == 0 || b == 0)
                    return 0;
                else if (long.MaxValue / b > a)
                    return (a * b) % mod;
                else
                {
                    long j0 = a / BMod;
                    long j1 = a % BMod;
                    long k0 = b / BMod;
                    long k1 = b % BMod;
                    long r = (((j0 * k1 + j1 * k0) % (mod / BMod)) * BMod + j1 * k1) % mod;
                    return r;
                }
            }

            public static Matrix MulMod(Matrix m1, Matrix m2, long mod)
            {
                Matrix result = new Matrix();
                result.A1 = (MulMod(m1.A1, m2.A1, mod) + MulMod(m1.A2, m2.A3, mod)) % mod;
                result.A2 = (MulMod(m1.A1, m2.A2, mod) + MulMod(m1.A2, m2.A4, mod)) % mod;
                result.A3 = (MulMod(m1.A3, m2.A1, mod) + MulMod(m1.A4, m2.A3, mod)) % mod;
                result.A4 = (MulMod(m1.A3, m2.A2, mod) + MulMod(m1.A4, m2.A4, mod)) % mod;
                return result;
            }

            public void Mod(long mod)
            {
                A1 %= mod; A2 %= mod; A3 %= mod; A4 %= mod;
            }

            public static Matrix PowerMod(long power, Matrix m, long mod)
            {
                Matrix modLast = m, result = new Matrix();

                while (power != 0)
                {
                    if ((power & 1) == 1)
                    {
                        if (result.A1 == 0)
                            result = modLast;
                        else
                            result = Matrix.MulMod(result, modLast, mod);
                    }

                    modLast = Matrix.MulMod(modLast, modLast, mod);
                    power >>= 1;
                }

                return result;
            }
        }

        struct Result
        {
            public long Index, Value;
            public int SIndex;
        }

        static void Main(string[] args)
        {
            long[] steps = new long[] { 60, 300, 1500, 15000, 150000, 1500000, 15000000, 150000000, 1500000000, 15000000000, 150000000000, 1500000000000, 15000000000000, 150000000000000, 1500000000000000, 15000000000000000 };
            long[] mods = new long[] { 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, 10000000000, 100000000000, 1000000000000, 10000000000000, 100000000000000, 1000000000000000, 10000000000000000 };

            long n = Convert.ToInt64(Console.ReadLine());
            int index = 0;
            long modValue = n % mods[index];

            Queue<Result> queue = new Queue<Result>();
            long[] fs = new long[60]; fs[1] = 1;

            for (int i = 2; i < fs.Length; i++)
            {
                fs[i] = (fs[i - 1] + fs[i - 2]) % mods[index];
                if (fs[i] == modValue)
                    queue.Enqueue(new Result { Index = i, Value = fs[i], SIndex = index });
            }

            List<Result> result = new List<Result>();

            while (queue.Count > 0)
            {
                Result current = queue.Dequeue();

                if (current.Value == n && current.SIndex == 12)
                {
                    result.Add(current);
                    continue;
                }
                else if (current.SIndex > 12)
                    continue;

                for (int i = 0; i * steps[current.SIndex] < steps[current.SIndex + 1]; i++)
                {
                    long nIndex = i * steps[current.SIndex] + current.Index;
                    long value = Cal(nIndex, mods[current.SIndex + 1]);

                    if (value == n % mods[current.SIndex + 1])
                        queue.Enqueue(new Result { Index = nIndex, SIndex = current.SIndex + 1, Value = value });
                }
            }

            if (result.Count == 0)
                Console.WriteLine(-1);
            else
            {
                long sIndex = result.Select(x => x.Index).Min();
                Console.WriteLine(sIndex);
            }
        }

        static long Cal(long index, long mod)
        {
            Matrix m = new Matrix { A1 = 1, A2 = 1, A3 = 1, A4 = 0 };
            Matrix power = Matrix.PowerMod(index, m, mod);
            return (long)power.A2;
        }
    }
}