import java.math.BigInteger;

public class Euler831 {

    static BigInteger[] mulTrunc(BigInteger[] a, BigInteger[] b) {
        BigInteger[] c = new BigInteger[6];
        for (int i = 0; i < 6; i++) {
            c[i] = BigInteger.ZERO;
        }
        for (int i = 0; i < 6; ++i) {
            if (a[i].equals(BigInteger.ZERO))
                continue;
            for (int j = 0; i + j < 6; ++j) {
                c[i + j] = c[i + j].add(a[i].multiply(b[j]));
            }
        }
        return c;
    }

    static BigInteger[] powPolyTrunc(BigInteger[] base, long exp) {
        BigInteger[] res = new BigInteger[6];
        for (int i = 0; i < 6; i++) {
            res[i] = BigInteger.ZERO;
        }
        res[0] = BigInteger.ONE;

        while (exp > 0) {
            if ((exp & 1) == 1) {
                res = mulTrunc(res, base);
            }
            exp >>= 1;
            if (exp > 0) {
                base = mulTrunc(base, base);
            }
        }
        return res;
    }

    static BigInteger hValue(long m) {
        BigInteger[] R = new BigInteger[6];
        R[0] = BigInteger.valueOf(1);
        R[1] = BigInteger.valueOf(3);
        R[2] = BigInteger.valueOf(5);
        R[3] = BigInteger.valueOf(5);
        R[4] = BigInteger.valueOf(3);
        R[5] = BigInteger.valueOf(1);

        BigInteger[] P = powPolyTrunc(R, m);

        int[] B = { 1, 5, 10, 10, 5, 1 };
        BigInteger h = BigInteger.ZERO;
        for (int i = 0; i < 6; ++i) {
            h = h.add(P[i].multiply(BigInteger.valueOf(B[5 - i])));
        }
        return h;
    }

    static String toBase7(BigInteger x) {
        if (x.equals(BigInteger.ZERO))
            return "0";
        StringBuilder s = new StringBuilder();
        BigInteger seven = BigInteger.valueOf(7);
        while (x.compareTo(BigInteger.ZERO) > 0) {
            BigInteger[] divRem = x.divideAndRemainder(seven);
            s.append(divRem[1].toString());
            x = divRem[0];
        }
        return s.reverse().toString();
    }

    public static String solve() {
        BigInteger h = hValue(142857);
        String s = toBase7(h);

        while (s.length() < 10) {
            s = "0" + s;
        }

        return s.substring(0, 10);
    }

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