import java.util.*;

class Euler56 {

    private static class Options {
        int aMax = 99;
        int bMax = 99;
        boolean runCheckpoints = true;
    }

    private static boolean parse_int_after_prefix(String arg, String prefix, int[] value) {
        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');
        }
        value[0] = parsed;
        return true;
    }

    private static boolean parseArguments(String[] args, Options options) {
        for (String arg : args) {
            if (arg.equals("--skip-checkpoints")) {
                options.runCheckpoints = false;
                continue;
            }
            int[] aValue = {options.aMax};
            if (parse_int_after_prefix(arg, "--a-max=", aValue)) {
                options.aMax = aValue[0];
                continue;
            }
            int[] bValue = {options.bMax};
            if (parse_int_after_prefix(arg, "--b-max=", bValue)) {
                options.bMax = bValue[0];
                continue;
            }

            System.err.println("Unknown argument: " + arg);
            return false;
        }

        return options.aMax >= 1 && options.bMax >= 1;
    }

    private static void multiplySmall(List<Integer> digits, int mul) {
        int carry = 0;
        for (int i = 0; i < digits.size(); i++) {
            int value = digits.get(i) * mul + carry;
            digits.set(i, value % 10);
            carry = value / 10;
        }
        while (carry > 0) {
            digits.add(carry % 10);
            carry /= 10;
        }
    }

    private static int digitSum(List<Integer> digits) {
        int sum = 0;
        for (int d : digits) {
            sum += d;
        }
        return sum;
    }

    private static int solve(int aMax, int bMax) {
        int best = 0;

        for (int a = 1; a <= aMax; a++) {
            List<Integer> value = new ArrayList<>();
            value.add(1);
            for (int b = 1; b <= bMax; b++) {
                multiplySmall(value, a);
                best = Math.max(best, digitSum(value));
            }
        }

        return best;
    }

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

    public static void main(String[] args) {
        Options options = new Options();
        if (!parseArguments(args, options)) {
            System.exit(1);
        }
        if (options.runCheckpoints && !runCheckpoints()) {
            System.exit(2);
        }

        System.out.println(solve(options.aMax, options.bMax));
    }
}
