import java.util.ArrayList;
import java.util.Collections;

public class Euler853 {

    static class Pair {
        long a, b;

        Pair(long a, long b) {
            this.a = a;
            this.b = b;
        }
    }

    static Pair fibPair(long n, long mod) {
        if (n == 0)
            return new Pair(0, 1 % mod);
        Pair p = fibPair(n >> 1, mod);
        long a = p.a;
        long b = p.b;

        java.math.BigInteger bia = java.math.BigInteger.valueOf(a);
        java.math.BigInteger bib = java.math.BigInteger.valueOf(b);
        java.math.BigInteger biba2 = bib.multiply(java.math.BigInteger.valueOf(2));

        java.math.BigInteger bic = biba2.subtract(bia);
        if (bic.compareTo(java.math.BigInteger.ZERO) < 0) {
            bic = bic.add(java.math.BigInteger.valueOf(mod));
        }
        bic = bia.multiply(bic).remainder(java.math.BigInteger.valueOf(mod));

        java.math.BigInteger bid = bia.multiply(bia).add(bib.multiply(bib))
                .remainder(java.math.BigInteger.valueOf(mod));

        long c = bic.longValue();
        long d = bid.longValue();

        if ((n & 1L) == 0)
            return new Pair(c, d);
        return new Pair(d, (c + d) % mod);
    }

    static ArrayList<Long> divisorsOf(long n) {
        ArrayList<Long> divs = new ArrayList<>();
        for (long d = 1; d * d <= n; ++d) {
            if (n % d == 0) {
                divs.add(d);
                if (d * d != n)
                    divs.add(n / d);
            }
        }
        Collections.sort(divs);
        return divs;
    }

    static boolean hasPeriod(long mod, long period, ArrayList<Long> properDivs) {
        Pair p = fibPair(period, mod);
        if (p.a != 0 || p.b != 1 % mod)
            return false;
        for (long d : properDivs) {
            Pair q = fibPair(d, mod);
            if (q.a == 0 && q.b == 1 % mod)
                return false;
        }
        return true;
    }

    static class Factor {
        long p;
        int e;

        Factor(long p, int e) {
            this.p = p;
            this.e = e;
        }
    }

    public static String solve() {
        long limit = 1000000000L;
        long period = 120;
        ArrayList<Long> properDivs = new ArrayList<>();
        for (long d : divisorsOf(period)) {
            if (d < period)
                properDivs.add(d);
        }

        Factor[] fac = {
                new Factor(2, 5), new Factor(3, 2), new Factor(5, 1),
                new Factor(7, 1), new Factor(11, 1), new Factor(23, 1),
                new Factor(31, 1), new Factor(41, 1), new Factor(61, 1),
                new Factor(241, 1), new Factor(2161, 1), new Factor(2521, 1),
                new Factor(20641, 1)
        };

        ArrayList<Long> divisors = new ArrayList<>();
        divisors.add(1L);

        for (Factor f : fac) {
            ArrayList<Long> next = new ArrayList<>();
            long pe = 1;
            for (int i = 0; i <= f.e; ++i) {
                for (long d : divisors) {
                    java.math.BigInteger v = java.math.BigInteger.valueOf(d).multiply(java.math.BigInteger.valueOf(pe));
                    if (v.compareTo(java.math.BigInteger.valueOf(limit)) < 0) {
                        next.add(v.longValue());
                    }
                }
                pe *= f.p;
            }
            divisors = next;
        }

        long ans = 0;
        for (long n : divisors) {
            if (n < 2)
                continue;
            if (hasPeriod(n, period, properDivs)) {
                ans += n;
            }
        }

        return Long.toString(ans);
    }

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