import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class Euler731 {
    static final long kBase = 10000000000L;

    public static String solve() {
        long n = 10000000000000000L;
        long nPlus9 = n + 9;

        List<Long> p3 = new ArrayList<>();
        p3.add(1L);
        while (p3.get(p3.size() - 1) <= nPlus9 / 3) {
            p3.add(p3.get(p3.size() - 1) * 3);
        }

        int limit = 0;
        for (int i = 1; i < p3.size(); ++i) {
            if (p3.get(i) <= nPlus9) {
                limit = i;
            }
        }

        if (limit == 0) {
            return "0000000000";
        }

        long sumQMod = 0;
        long[] remainders = new long[limit + 1];

        BigInteger bigBase = BigInteger.valueOf(kBase);
        BigInteger bigTen = BigInteger.TEN;

        for (int i = 1; i <= limit; ++i) {
            long d = p3.get(i);
            long m = nPlus9 - d;

            BigInteger bigD = BigInteger.valueOf(d);
            BigInteger modulus = bigD.multiply(bigBase);
            BigInteger bigM = BigInteger.valueOf(m);
            BigInteger s = bigTen.modPow(bigM, modulus);

            BigInteger[] divAndRem = s.divideAndRemainder(bigD);
            BigInteger q = divAndRem[0];
            BigInteger r = divAndRem[1];

            long qMod = q.remainder(bigBase).longValue();
            long rU64 = r.longValue();

            sumQMod = (sumQMod + qMod) % kBase;
            remainders[i] = rU64;
        }

        long denom = p3.get(limit);
        BigInteger numer = BigInteger.ZERO;
        for (int i = 1; i <= limit; ++i) {
            long scale = p3.get(limit - i);
            BigInteger term = BigInteger.valueOf(remainders[i]).multiply(BigInteger.valueOf(scale));
            numer = numer.add(term);
        }

        long carry = numer.divide(BigInteger.valueOf(denom)).longValue();
        long answer = (sumQMod + carry) % kBase;

        return String.format("%010d", answer);
    }

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