import java.math.BigInteger;
import java.util.*;

public class Euler934 {

    static List<Integer> sievePrimes(int limit) {
        boolean[] composite = new boolean[limit + 1];
        List<Integer> primes = new ArrayList<>();
        for (int i = 2; i <= limit; ++i) {
            if (!composite[i]) {
                primes.add(i);
                if ((long) i * i <= limit) {
                    for (int j = i * i; j <= limit; j += i) {
                        composite[j] = true;
                    }
                }
            }
        }
        return primes;
    }

    static long[] egcd(long a, long b) {
        if (b == 0)
            return new long[] { a, 1, 0 };
        long[] g = egcd(b, a % b);
        long x1 = g[1];
        long y1 = g[2];
        return new long[] { g[0], y1, x1 - (a / b) * y1 };
    }

    static long modInv(long a, long mod) {
        long[] g = egcd(a, mod);
        long r = g[1] % mod;
        if (r < 0)
            r += mod;
        return r;
    }

    static BigInteger solve(long N) {
        List<Integer> primes = sievePrimes(10000);
        List<Long> residues = new ArrayList<>();
        residues.add(0L);
        BigInteger modulus = BigInteger.ONE;

        BigInteger passCount = BigInteger.valueOf(N);
        BigInteger answer = BigInteger.ZERO;
        BigInteger bigN = BigInteger.valueOf(N);

        for (int pInt : primes) {
            long p = pInt;
            BigInteger bp = BigInteger.valueOf(p);
            BigInteger nextModulus = modulus.multiply(bp);

            long modP = modulus.remainder(bp).longValue();
            long inv = modInv(modP, p);

            List<Long> nextResidues = new ArrayList<>();
            for (long r : residues) {
                long rp = r % p;
                for (long a = 0; a < p; a += 7) {
                    long t = (((a + p - rp) % p) * inv) % p;

                    if (modulus.compareTo(bigN) > 0 && t != 0) {
                        continue;
                    }

                    BigInteger x = BigInteger.valueOf(r).add(modulus.multiply(BigInteger.valueOf(t)));
                    if (x.compareTo(bigN) <= 0) {
                        nextResidues.add(x.longValue());
                    }
                }
            }

            BigInteger nextCount = BigInteger.ZERO;
            if (nextModulus.compareTo(bigN) <= 0) {
                for (long r : nextResidues) {
                    if (r == 0) {
                        nextCount = nextCount.add(bigN.divide(nextModulus));
                    } else {
                        nextCount = nextCount
                                .add(bigN.subtract(BigInteger.valueOf(r)).divide(nextModulus).add(BigInteger.ONE));
                    }
                }
            } else {
                long count = 0;
                for (long r : nextResidues) {
                    if (r != 0)
                        count++;
                }
                nextCount = BigInteger.valueOf(count);
            }

            BigInteger failHere = passCount.subtract(nextCount);
            answer = answer.add(failHere.multiply(bp));

            if (nextCount.equals(BigInteger.ZERO)) {
                return answer;
            }

            residues = nextResidues;
            modulus = nextModulus;
            passCount = nextCount;
        }

        return BigInteger.ZERO;
    }

    public static String solve() {
        long N = 100000000000000000L;
        return solve(N).toString();
    }

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