public class Euler71 {
    static long gcd(long a, long b) {
        while (b != 0) {
            long t = b;
            b = a % b;
            a = t;
        }
        return a;
    }

    public static void main(String[] args) {
        long bestN = 0, bestD = 1;
        for (int d = 2; d <= 1000000; d++) {
            long n = (3L * d - 1) / 7;
            if (gcd(n, d) != 1)
                continue;
            if (n * bestD > bestN * d) {
                bestN = n;
                bestD = d;
            }
        }
        System.out.println(bestN);
    }
}
