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

class Euler65 {

    private static class Options {
        int term = 100;
        boolean runCheckpoints = true;
    }

    private static boolean parseIntAfterPrefix(String arg, String prefix, Options options) {
        if (!arg.startsWith(prefix)) {
            return false;
        }
        String tail = arg.substring(prefix.length());
        if (tail.isEmpty()) {
            return false;
        }

        int parsed = 0;
        for (int i = 0; i < tail.length(); i++) {
            char c = tail.charAt(i);
            if (c < '0' || c > '9') {
                return false;
            }
            parsed = parsed * 10 + (c - '0');
        }
        options.term = parsed;
        return true;
    }

    private static boolean parseArguments(String[] args, Options options) {
        for (String arg : args) {
            if (arg.equals("--skip-checkpoints")) {
                options.runCheckpoints = false;
                continue;
            }
            if (parseIntAfterPrefix(arg, "--term=", options)) {
                continue;
            }
            System.err.println("Unknown argument: " + arg);
            return false;
        }

        return options.term >= 1;
    }

    private static int coefficientForE(int index) {
        if (index == 0) {
            return 2;
        }
        if (index % 3 == 2) {
            return 2 * ((index + 1) / 3);
        }
        return 1;
    }

    private static BigInteger convergentNumerator(int term) {
        BigInteger numPrev = BigInteger.ONE;
        BigInteger num = BigInteger.valueOf(coefficientForE(0));
        BigInteger denPrev = BigInteger.ZERO;
        BigInteger den = BigInteger.ONE;

        if (term == 1) {
            return num;
        }

        for (int i = 1; i < term; i++) {
            int a = coefficientForE(i);
            BigInteger nextNum = BigInteger.valueOf(a).multiply(num).add(numPrev);
            BigInteger nextDen = BigInteger.valueOf(a).multiply(den).add(denPrev);
            numPrev = num;
            denPrev = den;
            num = nextNum;
            den = nextDen;
        }

        return num;
    }

    private static int digitSum(BigInteger x) {
        String s = x.toString();
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            sum += s.charAt(i) - '0';
        }
        return sum;
    }

    private static int solve(int term) {
        return digitSum(convergentNumerator(term));
    }

    private static boolean runCheckpoints() {
        if (solve(10) != 17) {
            System.err.println("Checkpoint failed for term=10");
            return false;
        }
        return true;
    }

    public static void main(String[] args) {
        Options options = new Options();
        List<String> argsList = new ArrayList<>();
        for (String arg : args) {
            argsList.add(arg);
        }

        if (!parseArguments(argsList.toArray(new String[0]), options)) {
            System.exit(1);
        }
        if (options.runCheckpoints && !runCheckpoints()) {
            System.exit(2);
        }

        System.out.println(solve(options.term));
    }
}
